I have a class with a definition of a private member like this:
[MyCustomAttribute]
private Func<String, String> MyFuncMember = (val) => val + " World! ";
and I’m trying to get the attribute that I put over it. Now, I have tried with Type.GetMembers(), Type.GetFields() and Type.GetMethods with the appropriate BindingFlags (BindingFlags.NonPublic) and I just cannot get that member. How can I retrieve it? Could it be a problem if the class where is defined is a sealed class?
Thanks in advance for you answers.
Try using this as your binding flags:
Without the
BindingFlags.Instanceflag it won’t be able to find your instance field.In general when you use
Type.GetFieldyou need to set:one (or both) of
BindingFlags.InstanceandBindingFlags.Staticand
BindingFlags.PublicandBindingFlags.NonPublic.The
|operator combines the flags using a binary or operation, meaning that both flags are set.