I need to see if a MemberInfo matches a particular BindingFlags. The closest method to this is Type#GetMember(string, BindingFlags).
I cannot find any method to do this.
I want to do something like this:
private List<MemberInfo> _members;
public IEnumerable<MemberInfo> GetMembers(BindingFlags flags)
{
foreach(var member in _members)
{
if(member.MatchesFlags(flags))
{
yield return member;
}
}
}
Actual types of
MemberInfoobtained with reflection (e.g. via callingMemberInfo[] GetMembers()onType) are:System.Reflection.RuntimeMethodInfoSystem.Reflection.RuntimeConstructorInfoSystem.Reflection.RuntimePropertyInfoSystem.Reflection.RtFieldInfoAll of them independently have property
BindingFlagsof typeBindingFlags. But the property is NonPublic. And the types areinternal sealed, that makes them inaccessible in normal code. Herereflectioncomes to rescue. To getBindingFlagsof aMemberInfoone can use such an extension:To find matches with
BindingFlagsthe following helper methods can be used:To test the solution one can use a class like this:
Then running:
gives: