在的GetType C#疑问,托管的CodeGen [英] C# doubt in GetType, Managed CodeGen

查看:199
本文介绍了在的GetType C#疑问,托管的CodeGen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑代码,

Type t0 = Type.GetType("System.Drawing.dll");
Type t1 = Type.GetType("System.Drawing.Font");

为了找到System.Drawing.Font大会System.Drawing中的类型这里。需要DLL。如何使用它?

Here in order to find type of "System.Drawing.Font" the assembly "System.Drawing.dll" is needed. how to use it.?

即笏,如果我这样做,所以该值的 T0 不会成为空。??

i.e wat if i do, so that value of t0 wont be null.??

考虑我AVE一个dll, proj.dll ,我需要找到类的类型 1级这是存在于DLL

Consider i ave a dll, proj.dll and i need to find the type of the class Class1 that is present in the dll.

推荐答案

指定的装配,包括强命名程序集的版本号:

Specify the assembly, including the version number for strongly named assemblies:

Type t = Type.GetType("System.Drawing.Font,System.Drawing,"+
                      " Version=2.0.0.0, Culture=neutral, "+
                      "PublicKeyToken=b03f5f7f11d50a3a");



当然,如果它的真正的只是系统.Drawing.Font (或其他类型的你知道在编译时),使用的typeof

Of course, if it's really just System.Drawing.Font (or another type you know at compile-time), use typeof:

Type t = typeof(System.Drawing.Font);

如果你知道在编译时在同一个装配另一种类型,可以使用的 Assembly.GetType

If you know another type in the same assembly at compile-time, you can use Assembly.GetType:

Type sizeType = typeof(System.Drawing.Size);
Assembly assembly = sizeType.Assembly;
Type fontType = assembly.GetType("System.Drawing.Font");

这篇关于在的GetType C#疑问,托管的CodeGen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆