calling Type.MakeGenericType() with null arguments

Go To


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:


But, you can't pass null types into MakeGenericType (see:

How do I achieve this?


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


Ok I avoided it like this:

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