Tuesday, February 24, 2009

BindingFlags.Static | BindingFlags.Instance

The reason we were not able to access the private FieldInfo with NonPublic was that you have to specify if it is a Static field or not (an ‘Instance’ field)

This combination will ensure that you get your field no matter what - BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance

Console.WriteLine(T.GetField(“a”, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance).GetValue(x));

No comments:

Post a Comment