C#——反射

System.Type 类

获取Type引用的3种方法
 1.Type t = typeof(double);
 2.double d =10.2;Type t = d.GetType();
 3.Type t = Type.GetType(string type);      //Type.GetType("System.Double");

System.Attribute 类

[AttributeUsage(AttributeTargets.Property,AllowMultiple=true,Inherited=false)]
public class FieldNameAttribute:Attribute
{
 private string name;
 public FieldNameAttribute(string name)
 {
  this.name = name;
 }
}

System.Reflection.Assembly 类

它允许访问给定程序集的元素据。 使用Assembly.Load()和Assembly.LoadFrom()加载程序集。
Assembly.Load("SomeAssemby");

查找定制特性. 调用Attribute.GetCustomAttribute();
所有的特性都是作为一般的Attribute引用来获取,若要调用为定制特性定义的任何方法或属性,需要显示转换为相关的定制特性类。

 

 

 

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章