关于类的 GetType 的 C# 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/629087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# question about GetType of class
提问by SyncMaster
I have an assembly asdf.dll and it has a class 'Class1'.
我有一个程序集 asdf.dll,它有一个类“Class1”。
How can I get the type of Class1?
如何获得 Class1 的类型?
string a = "Class1"; //Class1 is the name of class in asdf.dll
string typeString = typeof(Class1).FullName; // here I only have the string Class1 and not Class Class1
AssemblyName assemblyName = AssemblyName.GetAssemblyName("asdf.dll");
Type type = Type.GetType(typeString + ", " + assemblyName);
How can I get the type of a class from a string holding the class name?
如何从包含类名的字符串中获取类的类型?
采纳答案by leppie
Type t = Type.GetType("MyDll.MyClass,Mydll")
where MyDll.MyClass is the class Location of your desire class/Form. Mydll is the your dll name. which u want to Call.
其中 MyDll.MyClass 是您想要的类/表单的类位置。Mydll 是您的 dll 名称。你想打电话。
回答by leppie
typeof(Class1).FullName
is already the fully qualified name.
typeof(Class1).FullName
已经是完全限定名称。
Try just passing that, or using the Type.Name property instead.
尝试只传递它,或者改用 Type.Name 属性。