Reputation: 22760
I have this very simple test because the full version doesn't work either;
public class dfd
{
public string g { get; set; }
}
and then;
Type myType = typeof(dfd);
FieldInfo[] b = myType.GetFields(BindingFlags.Public);
When I look at b there is no field info.
{System.Reflection.FieldInfo[0]}
Any ideas?
Upvotes: 1
Views: 339
Reputation: 87228
You have an automatic public property, which defines a private field. If you ask for the non-public fields, you'll get the backing field of that property.
BTW, you need to ask for both BindingFlags.NonPublic | BindingFlags.Instance
, otherwise you won't retrieve that field.
Upvotes: 7