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引用來獲取,若要調用爲定製特性定義的任何方法或屬性,需要顯示轉換爲相關的定製特性類。

 

 

 

 


 

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