get assembly by class name

后端 未结 4 1024
青春惊慌失措
青春惊慌失措 2020-12-10 12:16

Is there any way to get the assembly that contains a class with name TestClass? I just know the class name, so I can\'t create an instance of that. And

4条回答
  •  一整个雨季
    2020-12-10 12:57

    Assembly asm = typeof(TestClass).Assembly;
    

    will get you the assembly as long as it is referenced. Otherwise, you would have to use a fully qualified name:

    Assembly asm = null;
    Type type = Type.GetType("TestNamespace.TestClass, ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
    if (type != null)
    {
        asm = type.Assembly;
    }
    

提交回复
热议问题