Reputation: 25
I have several protected readonly methods in a class that I need to retrieve so I can get the custom attributes. I am comfortable getting the custom attributes but how do I get the methods? This is the boiled down class:
public class TheParser
{
[myAttribute("test")]
protected readonly Parser<String> MyKeyWord;
}
And to get the methods I have tried many combinations using different BindingFlags but obviously I haven't found the right combination. Here is one attempt:
MethodInfo[] methods = typeof(TheParser).GetMethods(BindingFlags.NonPublic);
Upvotes: 0
Views: 43
Reputation: 65077
That isn't a method.. its a field.
Use GetFields
with NonPublic
and Instance
:
var fields = typeof(TheParser)
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var field in fields)
Console.WriteLine(field.Name); // prints "MyKeyWord"
Upvotes: 2