Mixedrealitytoolkit-unity: Problem with ReflectionExtensions and why is it needed?

Created on 24 Mar 2017  路  4Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Hello,

I faced an issue with holotoolkit today on Unity 5.5.1.f1
I had a line of code in one of my scripts that was
FieldInfo[] fieldArray = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

And when adding holotoolkit, the ReflectionExtensions raised an error when trying to build, due to the GetFields method returning an IEnumerable instead of an array in the extension.
I temporarily fixed the problem by doing this :
`#if UNITY_METRO && !UNITY_EDITOR
FieldInfo[] fieldArray = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToArray();

else

    FieldInfo[] fieldArray = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

endif`

as I need my code to be able to work with and without holotoolkit. But I was wondering why this extension is needed ? I guess it was useful at some point or on older versions of Unity maybe ? Or did I miss a detail somewhere ?

Thanks

Question

Most helpful comment

I faced same problem, and requested #577.

All 4 comments

I faced same problem, and requested #577.

So you proposed to move these extensions to a namespacen which should help. But are they all still needed in the end ? It doesn't seem like it to me

Did moving to the new namespace fix this issue?

I think keeping this class around is a good idea, because there are others that use this. It's just a tool for convenience.

Yes the move to the new namespace fixed the issue

Was this page helpful?
0 / 5 - 0 ratings