So I am trying to retrieve all private methods in my class that have a specific attribute. When I do
this.GetType().GetMethods()
This returns 18 methods, all of which are public. So I tried to modify it to use Binding flags like:
this.GetType().GetMethods(BindingFlags.NonPublic);
This causes zero results to come back. I then started playing around and I can't get any overrides of GetMethods(BindingFlags.x)
to work.
this.GetType().GetMethods(BindingFlags.Default); this.GetType().GetMethods(BindingFlags.Public);
All of those return zero results. What am I doing wrong?
You should pass BindingFlags.Instance in order to match instance methods:
this.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
You can also add BindingFlags.Static
to the flags if you want both instance and static methods.
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