How can I get the MethodInfo
for protected
and public
methods only?
using System.Linq;
using System.Reflection;
var methods = foo
.GetType()
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.Where(m => m.IsFamily || m.IsPublic);
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 MemberInfo
s and filter them out by IsFamily
and IsPublic
properties?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With