The dfiference between Type.GetProperty and Type.GetMembers is that both return private properties/members(which include properties), but GetMembers only of this type and not from base types whereas GetProperty also returns private properties of base types.
GetProperty:
Specify BindingFlags.NonPublic to include non-public properties (that is, private, internal, and protected properties) in the search.
GetMembers:
Specify BindingFlags.NonPublic to include non-public members (that is, private, internal, and protected members) in the search. Only protected and internal members on base classes are returned; private members on base classes are not returned.
So i guess that Age is an inherited property. If you would add BindingFlags.DeclaredOnly the result should be the same, you wouldn't see Age.
If you want to force GetMembers to include also private members of base types, use following extension method that loops all base types:
public static class TypeExtensions { public static MemberInfo[] GetMembersInclPrivateBase(this Type t, BindingFlags flags) { var memberList = new List<MemberInfo>(); memberList.AddRange(t.GetMembers(flags)); Type currentType = t; while((currentType = currentType.BaseType) != null) memberList.AddRange(currentType.GetMembers(flags)); return memberList.ToArray(); } }
Now your BindingFlags work already and even a private "inherited" Age property is returned:
MemberInfo[] allMembers = myObj.GetType().GetMembersInclPrivateBase(flags);
myObjobjis notmyObj- or is that a typo? Can you show a single snippet full (minimal) example that shows this behavior?