【问题标题】:Type.GetType() and Assembly.GetType() returns different resultsType.GetType() 和 Assembly.GetType() 返回不同的结果
【发布时间】:2014-01-24 01:14:30
【问题描述】:

以下代码导致不同的结果:

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) 却没有?

【问题讨论】:

  • T Dump&lt;T&gt;(T v) 来自LINQPad,它返回值并输出。

标签: c# .net types assemblies


【解决方案1】:

根据http://msdn.microsoft.com/en-us/library/y0cd10tb%28v=vs.110%29.aspxAssembly.GetType(string)需要类型的全名。

尝试在类型上使用FullName 而不是ToString() 来获取全名,而不是短名称。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    • 2020-02-17
    • 2011-10-02
    • 1970-01-01
    相关资源
    最近更新 更多