Exemple #1
0
 /// <summary>
 /// WARNING: Pubternal API (internal). Do not use. May change during any update.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="F"></typeparam>
 /// <param name="fieldInfo"></param>
 /// <returns></returns>
 public static Action <T, F> CreateFastFieldSetter <T, F>(FieldInfo fieldInfo)
 {
     if (ClrTypes.DynamicMethodDefinition != null)
     {
         return(CreateFastFieldSetterForCecil <T, F>(fieldInfo));
     }
     else
     {
         return(ReflectionEmitFastReflectionHelper.CreateFastFieldSetter <T, F>(fieldInfo));
     }
 }
Exemple #2
0
        private static Action <T, F> CreateFastFieldSetterForSRE <T, F>(FieldInfo fieldInfo)
        {
            try
            {
                return(ReflectionEmitFastReflectionHelper.CreateFastFieldSetter <T, F>(fieldInfo));
            }
            catch (Exception e2)
            {
                XuaLogger.Common.Warn(e2, "Failed creating fast reflection delegate through with reflection emit. Falling back to standard reflection...");

                return((target, value) => fieldInfo.SetValue(target, value));
            }
        }
Exemple #3
0
        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));
            }
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        private static Func <T, F> CreateFastFieldGetterForCecil <T, F>(FieldInfo fieldInfo)
        {
            try
            {
                return(CecilFastReflectionHelper.CreateFastFieldGetter <T, F>(fieldInfo));
            }
            catch (Exception e1)
            {
                try
                {
                    XuaLogger.Common.Warn(e1, "Failed creating fast reflection delegate through with cecil. Retrying with reflection emit...");

                    return(ReflectionEmitFastReflectionHelper.CreateFastFieldGetter <T, F>(fieldInfo));
                }
                catch (Exception e2)
                {
                    XuaLogger.Common.Warn(e2, "Failed creating fast reflection delegate through with reflection emit. Falling back to standard reflection...");

                    return((target) => (F)fieldInfo.GetValue(target));
                }
            }
        }