Language is C#.
Say i have overridden method in class A
class A:B
{
protected override void Method(BaseClass bc)
{
(DerivedClass)bc.DerivedClassField = blabla;
}
}
Is there any library/language feature/etc using which i can write following:
class A:B
{
protected override void Method(BaseClass bc)
{
bc.DerivedClassField = blabla;
}
}
by, for instance, adding some attribute to class A or something?
Sorry for crappy formatting.
You could use generics to do this in a type-safe way:
but this might cause other problems if you even want to use
A<T>without knowingT, in which case I would use the cast (if the class structure means the cast won’t fail) or redefine your object model.