private static FastReflectionDelegate GetFastDelegateForSRE(MethodBase method, bool directBoxValueAccess, bool forceNonVirtCall) { try { return(ReflectionEmitFastReflectionHelper.CreateFastDelegate(method, directBoxValueAccess, forceNonVirtCall));; } catch (Exception e2) { XuaLogger.Common.Warn(e2, "Failed creating fast reflection delegate through with reflection emit. Falling back to standard reflection..."); return((target, args) => method.Invoke(target, args)); } }
/// <summary> /// WARNING: Pubternal API (internal). Do not use. May change during any update. /// </summary> /// <param name="method"></param> /// <param name="directBoxValueAccess"></param> /// <param name="forceNonVirtCall"></param> /// <returns></returns> public static FastReflectionDelegate CreateFastDelegate(this MethodBase method, bool directBoxValueAccess = true, bool forceNonVirtCall = false) { var key = new FastReflectionDelegateKey(method, directBoxValueAccess, forceNonVirtCall); if (_MethodCache.TryGetValue(key, out FastReflectionDelegate dmd)) { return(dmd); } if (ClrTypes.DynamicMethodDefinition != null) { dmd = GetFastDelegateForCecil(method, directBoxValueAccess, forceNonVirtCall); } else { dmd = ReflectionEmitFastReflectionHelper.CreateFastDelegate(method, directBoxValueAccess, forceNonVirtCall); } _MethodCache.Add(key, dmd); return(dmd); }