Hi to All,
Suppose I would like to implement a generic class with three type
parameters:
class UniversalClass<TA, TB, TC>()
where TA: A, new()
where TB: B, new()
where TC: C, new()
The class has many 'use case' so it can be happen that TA or TB or TC (or TA
and TB or etc..)is meaningless. (similar to null actual parameters) There
are to many combinations
How can I instantiate a closed type instance from this generic in this cases
and how can I detect in UniversalClass's code this cases?
What I've tried:
I've created a NullTypeParamerer class for this purpose, and I test for it
in UniversalClass's constructor:
if( typeof(NullTypeParameter).IsAssignableFrom(typeof( TA)) ) {...}
My problem that in case I must use 'typeless' where clause like this:
class UniversalClass<TA, TB, TC>()
where TA: NullTypeParameter, new()
where TB: NullTypeParameter, new()
where TC: NullTypeParameter, new()
and all of A, B, C actual types must be inherited from NullTypeParameter. I
am not happy with this...
Any ideas?