获取指向给定类型的Type引用有三种方式:
typeof:Type t=typeof(double)
GetType():double D=10;Type t=D.GetType();
Type t=Type.GetType("System.Double");
1.Type的常用属性:
Name:数据类型名
FullName:数据类型的完整修饰名
Namespace:定义数据类型的名称空间名
用法:
Type IntType=typeof(Vector);
Console.WriteLine(IntType.IsAbstract);
Console.WriteLine(IntType.IsClass);
Console.WriteLine(IntType.IsEnum);
Console.WriteLine(IntType.IsPrimitive);
Console.WriteLine(IntType.IsValueType);
获得定义类型的装配件(程序集)引用:
Type t=typeof(Vector);
Assembly ConatainingAssembly=new Assembly(t);
Assembly类:
1。加载程序集:
Assembly assembly1=Assembly.Load("SomeAssembly");
Assembly assembly2=Assembly.LoadFrom(@"C:\SomeAssembly");
这个两个方法的区别在于一个是加载工程引用的程序集,一个是加载指定路径中的程序集。
获得程序集的名:string Type[] types=Assembly1.GetTypes();
foreach(Type type in types)
doSomething(type);
B.查找程序集中的定制属性:
Attribute[] DefinedAttributes=Attribute.GetCustomAttributes(Assembly1);
原文:http://everhow.blog.163.com/blog/static/357377320069113157432/