Reputation: 1927
I would like to use an abstract base class (call it AbstractBaseClassA) which holds only one property (virtual - Property1) of type List of another abstract base class (Call it AbstractBaseClassB).
I have another class which should inherit from AbstractBaseClassA (call it superClassA) and implement the property but as a List of class (type) that inherit from the AbstractBaseClassB (call it superClassB).
I would like the property of superClassA - Property1 override the property of AbstractBaseClassA - I can't use the override it because it is a List of elements that aren't from the same class (but from inherited class) and as so - it doesn't implement the abstract class, and when I use the "new" keyword - I get an error message claiming:
"There was an error reflecting property Member Property1: superClassA.Property1 of type System.Collections.Generic.List'1 hides base class member AbstractBaseClassA.Property1 of type System.Collections.Generic.List'1". The error occures when I try to serialize xml to superClassA object (I removed the xml Attributes).
What should I do in order to make it work ?
This is my code:
public abstract class AbstractBaseClassA
{
[XmlIgnore]
public virtual List<AbstractBaseClassB> Property1 {get; set;}
}
public Abstract class AbstractBaseClassB
{
public string simpleProperty1111 {get; set;}
/*constructors*/
public AbstractBaseClassB(){}
public AbstractBaseClassB(string prop1)
{
simpleProperty1111 = prop1;
}
}
public class superClassB : AbstractBaseClassB
{
public string simplePropety2222 {get; set;};
/*constructors*/
public superClassB() : base(){}
public superClassB(string prop22222, string prop11111) : base(prop11111)
{
simplePropety2222 = prop22222;
}
}
public class superClassA : AbstractBaseClassA
{
public new List<superClassB> Property1 {get; set;}
}
SOLVED : I've used the "virtual" (in abstract class) and the "new" keyword (in the inherited class) and I've changed the XmlAttribute over the virtual property with [XmlIgnore]
Upvotes: 1
Views: 154
Reputation: 1927
SOLVED: code in the question is updated: I've used the "virtual" (in abstract class) and the "new" keyword (in the inherited class) and I've changed the XmlAttribute over the virtual property with [XmlIgnore]
Upvotes: 0