I get null object when I am trying to reflect class’s static method under unit test. But it ok under editor’s Play Mode. My platform settings: Android, IL2CPP and .Net4.xHere is my class:
namespace Core.Easing
{
public class EasingFunction
{
public static float EaseNone(float t, float b, float c, float d)
{
return c * t / d + b;
}
}
}
and here is my reflection method:
public Func<float, float, float, float, float> Build()
{
var namespaceName = "Core.Easing";
var className = "EasingFunction";
var easeMethodName = "EaseNone";
var implType = Assembly.GetExecutingAssembly().GetType(namespaceName + "." + className);
//var implType = Type.GetType(namespaceName + "." + className);//Also not working
var implMethod = implType.GetMethod(easeMethodName, BindingFlags.Public | BindingFlags.Static);
var res = Delegate.CreateDelegate(typeof(Func<float, float, float, float, float>), implMethod);
return (Func<float, float, float, float, float>)res.Clone();
}
So, Each class has its own asmdef file and these are included in the unit test. I looked at the constraints from Unity’s documentation but couldn’t find an answer.