使用null参数调用Type.MakeGenericType()

And*_*ock 3 c# generics

我有一个通用类型:

MyType<T1, T2, T3>
Run Code Online (Sandbox Code Playgroud)

我想这样做:

typeof(MyType<,,>).MakeGenericType(new [] { null, null, string});
Run Code Online (Sandbox Code Playgroud)

所以我最终得到:

MyType<,,string>
Run Code Online (Sandbox Code Playgroud)

但是,您无法将空类型传递给MakeGenericType(请参阅:http://msdn.microsoft.com/en-us/library/system.type.makegenerictype.aspx).

我该如何实现这一目标?

谢谢

And*_*ock 5

好的,我避免这样:

var args = typeof(MyType<,,>).GetGenericArguments();
args[2] = typeof(string);
typeof(MyType<,,>).MakeGenericType(args);
Run Code Online (Sandbox Code Playgroud)