Getting MethodInfo for protected and public methods only?

There is no direct way. The thing you can do is check IsFamily and IsPublic flag of MethodInfo:

minfo = b.GetType().GetMethod("publicProtectedMember", 
        BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
if (minfo.IsFamily || minfo.IsPublic)
{
  string s = fd.Member();
}

Well, can't you just get all MemberInfos and filter them out by IsFamily and IsPublic properties?


using System.Linq;
using System.Reflection;

var methods = foo
    .GetType()
    .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
    .Where(m => m.IsFamily || m.IsPublic);

Tags:

C#

.Net