Given this class
public partial class Default : Page
{
private IRepository repo;
...
}
I want to find and set the private repo
field. Is that possible?
UPDATE
I tried using the GetFields(BindingFlags.NonPublic)
, it returns {System.Reflection.FieldInfo[0]}
.
UPDATE II
I tried using the GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
, it returns all the fields of the Page
but not repo
.
Use the GetFields
overload that allows you to specify flags:
GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
you can use the following code :
MemberInfo[] mi = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(MyType);
and convert FieldInfo fi = (FieldInfo) mi[i]; this code return Serializable Members (privates)
精彩评论