Hi,
i'm trying to solve the next problem ...
public class BaseType {...}
public class DerivedType : BaseType { ... }
public abstract class BaseClass
{
public abstract Type getGenericType();
}
public class DerivedClass<TheType: BaseClass where TheType : BaseType
{
public override Type GetGenericType()
{
return typeof(TheType);
}
}
.. . .
public class Example
{
public static void Main()
{
. . .
DerivedClass<DerivedTypeTransferedObject = new
DerivedClass<DerivedType>();
TheCall(TransferedObject);
}
public void TheCall(BaseClass AnObject)
{
Type GenericType = AnObject.GetGenericType();
// PROBLEM... this is what i tried to .. .
TheProcess(AnObject); // Cannot because C# doesn't suppor variance
for generic types
TheProcess((TheClass<GenericType>) AnObject); // Cannot because
GenericType is a variable, not a type
}
public void TheProcess(DerivedClass<BaseTypeValue)
{
. . .
}
}
----------------
So... I need to cast a reference from an ancestor type to a derived type
dynamically.
Maybe Reflection has the solution?
Any help will be appreciated.
Néstor.