How does one obtain programmatically a reference to the object of which a FieldInfo object is a field?
For example, I’d like something like this:
myFieldInfo.GetOwner(); // returns the object of which myFieldObject is a field
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unfortunately you can’t because the relationship works the opposite way. A FieldInfo object represents metadata that is independent of any instance. There is 1 FieldInfo for every instance of an object’s field.
This is true in general about all Metadata objects such as Type, FieldInfo, MethodInfo, etc … It is possible to use the metadata objects to manipulate an instance of an object. For instance FieldInfo can be used to grab an instance value via the GetValue method.
But a metadata object won’t ever be associated with an instance of the type.