I want to write a generic class that should be casted to itself with a different generic argument.
class Base {}
class Inherited : Base {}
class MyGeneric<T> {}
// WCF Service interface
void Foo(MyGeneric<Base> b);
// somewhere else
MyGeneric<Inherited> inherited;
Foo(inherited)
I know that this could be done in C# 4.0, but this doesn't help for now.
- I could write a specialized class for each
MyGeneric<T>
constellation, and there write an implicit type converter or implement a certain interface. But I want to avoid this. - I could have an interface with no generic, but the whole sense of the generic in this case is to get compile time type safety on the method Foo. So this is not an option.
- Because Foo is a Operation Contract, it could not be generic itself.
Any ideas how this problem could be solved in C# 3.0?