Mama Tate Mama Tate - 1 year ago 52
C# Question

Get an object instance from FieldInfo

So my problem is this: I have an object instance represented only by FieldInfo. I have no other access to that object. Is it possible to get that object instance only through the field info like so?

MyObject myObject = fieldInfo.SomeMethodOrProperty as MyObject;

This is just only an illustration, but I think you get the picture.

Answer Source

No, the FieldInfo represents attributes and metadata of a field in regards to a type. It is not attached to a specific instance. When you want to use it, you have to pass in the instance you want it to use (through GetValue or SetValue)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download