tags:

views:

60

answers:

3

How to get MethodInfo of protected and public methods only?

Please advise.

+2  A: 

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

Fyodor Soikin
+1  A: 

There is no directway the thing you can do it check isfamily and ispublic flag of methodinfo

    minfo = b.GetType().GetMethods("publicProtectedMember", 
BindingFlags.Instance|BindingFlags.NonPublic |BindingFlags.Public);
                if (minfo.IsFamily || minfo.IsPublic)
                {
                    string s = fd.Member();
                }
Pranay Rana
`GetMethods` not just `GetMethod` I guess
abatishchev
A: 
using System.Linq;
using System.Reflection;

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