how to get both fields and properties in single call via reflection?

How about:

const BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.Instance;
MemberInfo[] members = type.GetFields(bindingFlags).Cast<MemberInfo>()
    .Concat(type.GetProperties(bindingFlags)).ToArray();

Alternatively, libraries like FastMember will work happily with either fields or properties, with get/set identical regardless of the member-type.

Leave a Comment