Get all fields from a class : Reflection Assembly : Development Class C# Source Code


Custom Search

C# Source Code » Development Class » Reflection Assembly »

 

Get all fields from a class









    


using System;
using System.Reflection;


public class Test
{
    public static void Main(string[] args)
    {
    TheType.MyClass aClass = new TheType.MyClass();

    Type t = aClass.GetType();
    FieldInfo[] fi = t.GetFields();
    foreach(FieldInfo field in fi)
      Console.WriteLine("Field: {0}", field.Name);
    }
}



namespace TheType {
    public interface IFaceOne {
      void MethodA();
    }
    
    public interface IFaceTwo {
      void MethodB();
    }
    
    public class MyClass: IFaceOne, IFaceTwo {
      public int myIntField;
      public string myStringField;
        private double myDoubleField = 0;
        
        
        public double getMyDouble(){
          return myDoubleField;
        }
        
      public void myMethod(int p1, string p2)
      {
      }
    
      public int MyProp
      {
        get { return myIntField; }
        set { myIntField = value; }
      }
    
      public void MethodA() {}
      public void MethodB() {}
    }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Development Class
» Reflection Assembly