Deeper Reflection: iterate through the fields of the class : Field « Reflection « C# / CSharp Tutorial






using System;
using System.Reflection;

class MyClass
{
    MyClass() {}
    static void Process()
    {
    }
    
    public int MyFunction(int i, Decimal d, string[] args)
    {
        return(0);
    }
    public int        value = 0;
    public float        log = 1.0f;
    public static int    value2 = 44;
}

class MainClass
{    
    public static void Main(String[] args)
    {
        // 
        Console.WriteLine("Fields of MyClass");
        Type t = typeof (MyClass);
        foreach (MemberInfo m in t.GetFields())
        {
            Console.WriteLine("{0}", m);
        }
        
    }
}
Fields of MyClass
Int32 value
Single log
Int32 value2








19.4.Field
19.4.1.Get all fields from a Type
19.4.2.List Fields
19.4.3.Deeper Reflection: iterate through the fields of the class
19.4.4.Get/set a field using a FieldInfo
19.4.5.Reflecting On Members Of A Type
19.4.6.Get Type full name and base type and its members