Hi Again Marc,
sorry to bother you again, I seemed to block in another point, I did
has you suggested and it worked very well.
Now I'm facing another problem, serialization :(
This is what I've done:
[XmlArray("UserDefinedAttributes")]
[XmlArrayItem("UserDefinedAttribute")]
public ArrayList XmlAttributes
{
get {
ArrayList output = new ArrayList();
if (attributes != null)
{
foreach (IUserDefinedAttributes
tmpUserDefinedAttributes in this.attributes)
{
Type typeOfUDA = tmpUDA.Type;
if (typeOfUDA == typeof(string))
output.Add((UserDefinedAttribute<string>)tmpUDA);
else if (typeOfUDA == typeof(int))
output.Add((UserDefinedAttribute<int>)tmpUDA);
else if (typeOfUDA == typeof(float))
output.Add((UserDefinedAttribute<float>)tmpUDA);
else if (typeOfUDA == typeof(DateTime))
output.Add((UserDefinedAttribute<DateTime>)tmpUDA) ;
else if (typeOfUDA == typeof(TimeSpan))
output.Add((UserDefinedAttribute<TimeSpan>)tmpUDA) ;
else if (typeOfUDA == typeof(bool))
output.Add((UserDefinedAttribute<bool>)tmpUDA);
else
output.Add((UDA<object>)tmpUDA);
}
}
return output;
}
set {
ArrayList input = value;
this.attributes = new List<IUserDefinedAttribute>();
foreach (IUserDefinedAttribute tmpUDA in input)
{
attributes.Add(tmpUDA);
}
}
}
[XmlIgnore]
public List<IUserDefinedAttributeAttributes
{
get {return this.attributes;
}
set { this.attributes = value; }
}
It seems that a list of interfaces would not work since it seems that
only "real" classes can be serialized, so I created an array list,
catch the type and the serialization seems to work correctly, the
problems appear when the deserialization occur, for some reason, it
seems that the deserialization for this property doesn't occur, and
unfortunately, if I try to set the type of the ArrayItem
(IUserDefinedAttribute) it will not work because IUserDefinedAttribute
is an interface.
Is it possible to overcome this? (If I set a breakpoint on the set
method, it not even being called)
On Jun 19, 12:52*pm, Marc Gravell <marc.grav...@gmail.comwrote:
Right; in this case, I might have a non-generic interface to use -
soemthing like IUserDefinedType below. Then you can have a list of
IUserDefinedType. That is the probably closest you can get if the T can
change per item in the list.
Note also that there are other ways of modelling flexible properties -
for example, if you use data-binding, System.ComponentModel allows you
to have runtime properties via ICustomTypeDescriptor or
TypeDescriptionProvider. Quite an involved area, but if you make use of
data-binding, let me know - I can give you some hints to get this working....
Marc
public interface IUserDefinedType
{
* * *object Value { get; set; }
* * *Type Type { get; }}
public interface IUserDefinedType<T: IUserDefinedType
{
* * *new T Value { get; set; }}
public class UserDefinedType<T: IUserDefinedType<T>
{
* * *public T Value { get; set; }
* * *public Type Type { get { return typeof(T); } } // or whatever
* * *object IUserDefinedType.Value
* * *{
* * * * *get { return Value; }
* * * * *set { Value = (T)value; }
* * *}
}- Hide quoted text -
- Show quoted text -