1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| namespace ConsoleApp7 { class MyClass { public int intIndex1; public float floatIndex1; private int intIndex2;
public int prop1 { get { return 1; } }
private int prop2 { get { return 2; } }
public void func1(){}
private void func2(){} } } ------------------------------------------------------------------------------------------------------------------------- namespace ConsoleApp7 { class Program { static void Main(string[] args) { MyClass myClass = new MyClass();
Type type = myClass.GetType(); Console.WriteLine(type.Name); Console.WriteLine(type.Namespace); Console.WriteLine(type.Assembly);
Console.WriteLine("type.GetFields()"); FieldInfo[] FieldArrays = type.GetFields(); foreach (FieldInfo info in FieldArrays) { Console.WriteLine(info.Name); }
Console.WriteLine("type.GetProperties()"); PropertyInfo[] PropertyArrays = type.GetProperties(); foreach (PropertyInfo info in PropertyArrays) { Console.WriteLine(info.Name); }
Console.WriteLine("type.GetMethods()"); MethodInfo[] MethodArrays = type.GetMethods(); foreach (MethodInfo info in MethodArrays) { Console.WriteLine(info.Name); }
Console.ReadKey(); } } } ------------------------------------------------------------------------------------------------------------------------- 输出: MyClass ConsoleApp7,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null type.GetFields() intIndex1 floatIndex1 type.GetProperties() prop1 type.GetMethods() get_prop1 func1 GetType ToString Equals GetHashCode
|