例如,在 .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.
}