Пример #1
0
        /// <summary>
        /// Aspect method to use for method call substition
        /// </summary>
        /// <param name="typeBuilder"></param>
        /// <param name="il"></param>
        /// <param name="method"></param>
        /// <param name="replaceMethod">Replace Method</param>
        /// <returns></returns>
        internal bool MethodCall(Mono.Cecil.TypeDefinition typeBuilder, Mono.Cecil.Cil.ILProcessor il, Mono.Cecil.MethodDefinition method, Mono.Cecil.MethodDefinition replaceMethod)
        {
            if (!replaceMethod.IsStatic)
            {
                return(false);
            }

            var        attrs = method.GetCustomAttributes <StaticMethodReplacerAttribute>();
            MethodInfo meth  = null;

            foreach (var attr in attrs)
            {
                var staticType = attr.staticMethodType;
                var smeth      = staticType.GetMethod(replaceMethod.Name, BindingFlags.Static | BindingFlags.Public);

                if (smeth != null)
                {
                    meth = smeth;
                }
            }

            if (meth == null)
            {
                return(false);
            }

            il.Emit(Mono.Cecil.Cil.OpCodes.Call, meth);

            return(true);
        }