What’s wrong with this reflection code? GetFields() is returning an empty array

The parameterless GetFields() returns public fields. If you want non-public ones, use:

cc.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic);

or whatever appropriate combination you want – but you do need to specify at least one of Instance and Static, otherwise it won’t find either. You can specify both, and indeed public fields as well, to get everything:

cc.GetType().GetFields(BindingFlags.Instance | 
                       BindingFlags.Static |
                       BindingFlags.NonPublic |
                       BindingFlags.Public);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)