I’m trying to use Reflection to instantiate Objects.
The issue I’m running into is that all public fields are returned as type MonoField and not as their actual String or int types. It seems to be causing System.Reflection.FieldInfo.SetValue to not be casting my object correctly. I’m unsure what a Monofield is, it’s not in the MSDN, and I’m assuming it has to do with Mono as a .NET framework. I can’t find any information on it or what it is for/can do with it.
It seems to be blocking the use of Reflection, and I’m curious if there are any workaround for it.
I’m a .NET developer about to start investigating Unity to see if we can use it. So I stumbled upon this to see if it supports reflection (I guess it does, thanks Ntero!).
I see this same issue often from people developing .NET applications when diving into reflection. Every object has a “GetType” method which returns the type of that object. So the FieldInfo object was returning its type “MonoField” when you called GetType. However, that MonoField object has the property “TypeInfo” which you found which is what is supposed to be used to inform you of that reflected field’s type. So just be aware of its use (GetType is infinitely useful) and what it means especially when using reflection. Good luck in your development!