How to get the value of a private member using reflection C# 4
I am trying to get the private member's value (Text) from NumericUpDown.
public class NumericUpDown
{
private TextBox Text;
...
...
}
I am not understanding why it's not showing as a field. Maybe someone could clarify the difference between fields and members. If it was a field I have found that using reflection I can get it by:
typeof(NumericUpDown).GetField("Text", BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(t开发者_如何学JAVAhis) As TextBox
but it's a member so I have to get the MemberInfo by:
typeof(NumericUpDown).GetMember("Text", BindingFlags.FlattenHierarchy | BindingFlags.NonPublic | BindingFlags.Instance).GetValue(0)
this does not return the value, but a string with the type. Which would make sense, because It's the value of the memberinfo, but I want the actual value of the actual object.
Is there any way of retrieving it like FieldInfo.GetValue(object)? Any help or suggestions. Thanks in advance.
This is because you are using Silverlight.
Quote: Silverlight reflection cannot be used to bypass access level restrictions and (for example) invoke private members.
精彩评论