Get a link to a variable from the FieldInfo field

I am working on a project in which a field name from XML is loaded, and a field with that name is returned and added to the current object. The problem is that FieldInfo.GetValue seems to return the current value of the field, not the link. Is there any way around this?

+6
c # mono
source share
1 answer

No, unfortunately, no. The construction of FieldInfo.GetValue is to provide a value, not a link. On FieldInfo there is no other suitable method for providing a link.

One of the reasons that it will be simply unsafe. Imagen is a script in which an object is a struct on the stack. If a FieldInfo can provide a link to the field of this struct , then it will provide a link to a piece of the stack that can go at any time. Reading or writing this link after stacking will be wrong and type violation.

+7
source share

All Articles