This compiles:
class ReplicatedBaseType
{
}
class NewType: ReplicatedBaseType
{
}
class Document
{
ReplicatedBas
Variance exists in C# 4.0 targetting .NET 4), but is limited to interfaces and usage of in/out (oh, and arrays of reference-types). For example, to make a covariant sequence:
class DalBase : IEnumerable where T: ReplicatedBaseType
{
public IEnumerator GetEnumerator() {throw new NotImplementedException();}
IEnumerator IEnumerable.GetEnumerator() { throw new NotImplementedException(); }
}
class DocumentTemplate
{
IEnumerable BaseCollection;
DocumentTemplate()
{
BaseCollection = new DalBase(); // Error in this line. It seems this is not possible
}
}
But other than that... no. Stick to either non-generic lists (IList), or use the expected list type.