Exemplo n.º 1
0
 public static IEnumerable<System.Reflection.FieldInfo> GetAllFields(Object obj)
 {
     System.Reflection.BindingFlags fieldFlags =
         //System.Reflection.BindingFlags.FlattenHierarchy |
         System.Reflection.BindingFlags.DeclaredOnly |
         System.Reflection.BindingFlags.GetField |
         System.Reflection.BindingFlags.Instance |
         System.Reflection.BindingFlags.NonPublic |
         System.Reflection.BindingFlags.Public |
         System.Reflection.BindingFlags.Static;
     System.Reflection.FieldInfo[] fields = new System.Reflection.FieldInfo[] { };
     //fields.Concat(fields);
     // move up through hierarchy to look for field
     Type objType = obj.GetType();
     while (objType != null)
     {
         fields = fields.Concat(objType.GetFields(fieldFlags)).ToArray();
         objType = objType.BaseType;
     }
     return fields;
 }