calling Type.MakeGenericType() with null arguments

Go To StackoverFlow.com

3

I have a generic type:

MyType<T1, T2, T3>

and i want to do this:

typeof(MyType<,,>).MakeGenericType(new [] { null, null, string});

so i end up with:

MyType<,,string>

But, you can't pass null types into MakeGenericType (see: http://msdn.microsoft.com/en-us/library/system.type.makegenerictype.aspx).

How do I achieve this?

Thanks

2009-06-16 10:10
by Andrew Bullock
Why do you want to do this? Are you adding in the other types later on - thecoop 2009-06-16 18:42
i need to support open generic types, i have rules to apply to MyTypes based on their generic arguments. so a MyType would get the Mytype<,,z> rule applied to it - Andrew Bullock 2009-06-18 08:01


5

Ok I avoided it like this:

var args = typeof(MyType<,,>).GetGenericArguments();
args[2] = typeof(string);
typeof(MyType<,,>).MakeGenericType(args);
2009-06-16 10:19
by Andrew Bullock
Ads