【发布时间】:2010-09-07 18:51:13
【问题描述】:
例如在 .NET app.config 中,您可能会得到
<configuration>
<configSections>
<section name="MyConfig" type="MyAssembly.MyType, MyAssembly, PublicKeyToken=null" />
</configSections>
...
</configuration>
类型部分中的签名似乎在各种 .NET 地方都已标准化,但我不知道如何在我自己的程序中执行此操作。我在我的程序中使用了System.Activator,但这感觉就像我在复制 .NET 已经完成的工作。
在编程方面我该怎么做:
void Main()
{
object instance = CreateInstance("MyAssembly.MyType, MyAssembly, PublicKeyToken=null");
Console.WriteLine(instance.GetType().Name);
}
object CreateInstance(string dotNetTypeSignature)
{
// Code goes here.
}
【问题讨论】:
-
顺便说一下,这叫做装配限定名称。
-
谢谢,我会将这个词添加到我的词汇中。
标签: c# .net reflection late-binding