using System; using System.Collections.Generic; using System.Linq; using System.Reflection; public static class ReflectionExtensions { public static IEnumerable GetAllFields(this Type type) { if (type == null) { return new List(); } BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; return type.GetFields(flags).Concat(GetAllFields(type.BaseType)); } public static FieldInfo GetAllField(this Type type, string fieldName) { if (type == null) { return null; } BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance; return type.GetField(fieldName, flags) ?? GetAllField(type.BaseType, fieldName); } }