Call Type.MakeGenericType () with null arguments

I have a generic type:

MyType<T1, T2, T3>

and I want to do this:

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

so i get:

MyType<,,string>

But you cannot pass null types to MakeGenericType (see: http://msdn.microsoft.com/en-us/library/system.type.makegenerictype.aspx ).

How do I achieve this?

thanks

+3
source share
1 answer

Ok, I avoided this:

var args = typeof(MyType<,,>).GetGenericArguments();
args[2] = typeof(string);
typeof(MyType<,,>).MakeGenericType(args);
+5
source

Source: https://habr.com/ru/post/1710559/


All Articles