I would like to declare a property as:
IList<BaseNode and IComplexType> ComplexTypes { get; }
All elements in the list inherit from BaseNode and implement IComplexType. Is there any way to do this? It won't work to create a class BaseNodeComplexType because the nodes in the list are all sub-classes of BaseNode.
Update: I didn't think this through to explain fully. I have sub classes such as XmlNode. XmlNode inherits from BaseNode. I also have XmlComplexNode that inherits from XmlNode and implements IComplexType. But XmlNode does not inherit from IComplexType (and I don't want it to as I use "obj is IComplexType" in places. apologies for not adding this originally.
No, but you could solve it with generics?
class CustomObj<T> where T : BaseNode, IComplexType
{
IList<T> ComplexTypes { get; }
}
For more details about the used generic-constraints, see this page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With