以下代码会产生不同的结果:
class X<R>
{
public class Y { }
}
...
var t = typeof(X<int>.Y);
var n = t.ToString().Dump(); // <- X`1+Y[System.Int32]
Type.GetType(n).Dump(); // <-- X`1+Y[System.Int32]
t.Assembly.GetType(n).Dump(); // <-- null
为什么 Type.GetType(n)
找到类型,但 t.Assembly.GetType(n)
找不到?
最佳答案
根据http://msdn.microsoft.com/en-us/library/y0cd10tb%28v=vs.110%29.aspx ,Assembly.GetType(string)
需要类型的完整名称。
尝试在类型上使用 FullName
而不是 ToString()
来获取全名,而不是短名称。
关于c# - Type.GetType() 和 Assembly.GetType() 返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20953267/