Hello,
I'm currently playing around with the XmlSerializer to replace my old
handmade Xml parsing code, but am having a few small issues with
default values and derived classes.
Say we have classes A, B and C:
abstract class A
{
protected int a_value = 1;
[XmlAttribute("value"), DefaultValue(1)]
public int AValue
{
get { return a_value; }
set { a_value = value; }
}
}
class B : A
{
....
}
class C : A
{
....
}
Now, I want class B and C to have different default values, more
precisely, I want B to have 1 as default value and C to have
Int32.MaxValue. But I can't figure out how to actually make this work.
I tried making the property in A abstract and provide the
implementation in B and C with different default values, but it still
used the default value from A. I tried removing the default value from
A, which gave the result of having no default value, everything was
printed, always.
I then tried to remove the XmlAttribute attribute from A and only have
it and the default value in B and C, but it gave me the following
exception:
System.InvalidOperationException: There was an error reflecting
property 'AValue'. ---> System.InvalidOperationException: Member
B.AValue' hides inherited member 'A.AValue', but has different custom
attributes.
Anyone have any ideas for this? :-)
Thanks,
- Rasmus.