ExtendRealityLtd / Malimbe

[Obsolete - No longer maintained] A collection of tools to simplify writing public API components for the Unity software.
MIT License
51 stars 11 forks source link

Fix null-coalescing and null-conditional operator usage with UnityEngine.Object #13

Open bddckr opened 5 years ago

bddckr commented 5 years ago

https://blogs.unity3d.com/2014/05/16/custom-operator-should-we-keep-it/

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-coalescing-operator https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-conditional-operators


IL to match is pretty much just some form of value/field load followed by a brtrue/brtrue.s. The latter just needs to be replaced with a call to [UnityEngine.CoreModule]UnityEngine.Object::op_Inequality(class [UnityEngine.CoreModule]UnityEngine.Object, class [UnityEngine.CoreModule]UnityEngine.Object) and a brfalse/brfalse.s afterwards. Only do this when the loaded value/field is inheriting from UnityEngine.Object of course.