c#之反射_Type_Fieldinfo[]小記
using System;
using System.Reflection;//反射
public class FieldInfoClass
{
public int myField1 = 0;
protected string myField2 = null;//保護成員,class and subclass can access
public static void Main() //static main method
{
FieldInfo[] myFieldInfo;//陣列類
Type myType = typeof(FieldInfoClass);//自生類的類型別提取
// Get the type and fields of FieldInfoClass.
//基於以上自生類型別提取類的屬性,返回fieldinfo[]
//由type.getfields方法返回fieldinfo型別,由此可以提取類的相關屬性定義資訊
//方法參數列示SEARCH的範圍
myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance
| BindingFlags.Public);
Console.WriteLine("\nThe fields of " +
"FieldInfoClass are \n");
// Display the field information of FieldInfoClass.
//fieldinfo[].length提取類型別中屬性的個數
for (int i = 0; i < myFieldInfo.Length; i++)
{
Console.WriteLine("\nName : {0}", myFieldInfo[i].Name);
Console.WriteLine("Declaring Type : {0}", myFieldInfo[i].DeclaringType);
Console.WriteLine("IsPublic : {0}", myFieldInfo[i].IsPublic);
Console.WriteLine("MemberType : {0}", myFieldInfo[i].MemberType);
Console.WriteLine("FieldType : {0}", myFieldInfo[i].FieldType);
Console.WriteLine("IsFamily : {0}", myFieldInfo[i].IsFamily);
Console.ReadKey();
}
}
}
using System.Reflection;//反射
public class FieldInfoClass
{
public int myField1 = 0;
protected string myField2 = null;//保護成員,class and subclass can access
public static void Main() //static main method
{
FieldInfo[] myFieldInfo;//陣列類
Type myType = typeof(FieldInfoClass);//自生類的類型別提取
// Get the type and fields of FieldInfoClass.
//基於以上自生類型別提取類的屬性,返回fieldinfo[]
//由type.getfields方法返回fieldinfo型別,由此可以提取類的相關屬性定義資訊
//方法參數列示SEARCH的範圍
myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance
| BindingFlags.Public);
Console.WriteLine("\nThe fields of " +
"FieldInfoClass are \n");
// Display the field information of FieldInfoClass.
//fieldinfo[].length提取類型別中屬性的個數
for (int i = 0; i < myFieldInfo.Length; i++)
{
Console.WriteLine("\nName : {0}", myFieldInfo[i].Name);
Console.WriteLine("Declaring Type : {0}", myFieldInfo[i].DeclaringType);
Console.WriteLine("IsPublic : {0}", myFieldInfo[i].IsPublic);
Console.WriteLine("MemberType : {0}", myFieldInfo[i].MemberType);
Console.WriteLine("FieldType : {0}", myFieldInfo[i].FieldType);
Console.WriteLine("IsFamily : {0}", myFieldInfo[i].IsFamily);
Console.ReadKey();
}
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-705449/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- c#之menustrip小記(1)C#
- c#之readonly小記C#
- c#之泛型小記C#泛型
- c#之word物件模型小記C#物件模型
- c#之menustrip_toolstripmenuitem小記C#UI
- c#之tcbs struct(2)小記C#Struct
- c#之tcbs class的小記C#
- c#之引用office功能元件_小記C#元件
- c#之結構struct(2)_小記C#Struct
- c#之stream相關類小記C#
- c#之反射_FieldInfo_GetField_C#反射
- c#之資料型別小測記C#資料型別
- c#之tcbs 建構函式小記C#函式
- C#反射C#反射
- c#之基類派生類base_小記C#
- c#之datagridview控制元件(1)_小記C#View控制元件
- c#之arraylist動態陣列小記(1)C#陣列
- C#小筆記C#筆記
- C# 反射(Reflection)C#反射
- c#之基類派生類base_小記(2)C#
- Java筆記-反射機制(三)-小demoJava筆記反射
- C#反射優化C#反射優化
- C# 反射詳解C#反射
- c# 反射呼叫方法C#反射
- c#之互操作性_(非)託管程式碼小記C#
- java反射小例子Java反射
- C#反射(System.Reflection )C#反射
- 轉c#反射技術C#反射
- java反射之動態代理學習筆記Java反射筆記
- C# 反射/對映學習C#反射
- Unity C# 反射效能優化UnityC#反射優化
- 【C#】:淺談反射機制C#反射
- C#利用反射建立例項C#反射
- C#高階–反射詳解C#反射
- 什麼是C#反射(Reflection)C#反射
- Java之反射Java反射
- 【C#學習之辨析小總結】C#
- c#呼叫儲存過程小記C#儲存過程