CallMethod() public static method

public static CallMethod ( this generator, MethodInfo methodInfo ) : void
generator this
methodInfo System.Reflection.MethodInfo
return void
コード例 #1
0
        internal static void GenerateCreateSetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)
        {
            MethodInfo setMethod = propertyInfo.GetSetMethod(true);

            if (!setMethod.IsStatic)
            {
                ILGeneratorExtensions.PushInstance(generator, propertyInfo.DeclaringType);
            }
            generator.Emit(OpCodes.Ldarg_1);
            ILGeneratorExtensions.UnboxIfNeeded(generator, propertyInfo.PropertyType);
            ILGeneratorExtensions.CallMethod(generator, setMethod);
            ILGeneratorExtensions.Return(generator);
        }
コード例 #2
0
        private void GenerateCreateGetPropertyIL(PropertyInfo propertyInfo, ILGenerator generator)
        {
            MethodInfo getMethod = propertyInfo.GetGetMethod(true);

            if (getMethod == null)
            {
                throw new ArgumentException(StringUtils.FormatWith("Property '{0}' does not have a getter.", (IFormatProvider)CultureInfo.InvariantCulture, (object)propertyInfo.Name));
            }
            if (!getMethod.IsStatic)
            {
                ILGeneratorExtensions.PushInstance(generator, propertyInfo.DeclaringType);
            }
            ILGeneratorExtensions.CallMethod(generator, getMethod);
            ILGeneratorExtensions.BoxIfNeeded(generator, propertyInfo.PropertyType);
            ILGeneratorExtensions.Return(generator);
        }
コード例 #3
0
        private void GenerateCreateMethodCallIL(MethodBase method, ILGenerator generator)
        {
            ParameterInfo[] parameters = method.GetParameters();
            Label           label      = generator.DefineLabel();

            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Ldlen);
            generator.Emit(OpCodes.Ldc_I4, parameters.Length);
            generator.Emit(OpCodes.Beq, label);
            generator.Emit(OpCodes.Newobj, typeof(TargetParameterCountException).GetConstructor(ReflectionUtils.EmptyTypes));
            generator.Emit(OpCodes.Throw);
            generator.MarkLabel(label);
            if (!method.IsConstructor && !method.IsStatic)
            {
                ILGeneratorExtensions.PushInstance(generator, method.DeclaringType);
            }
            for (int index = 0; index < parameters.Length; ++index)
            {
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Ldc_I4, index);
                generator.Emit(OpCodes.Ldelem_Ref);
                ILGeneratorExtensions.UnboxIfNeeded(generator, parameters[index].ParameterType);
            }
            if (method.IsConstructor)
            {
                generator.Emit(OpCodes.Newobj, (ConstructorInfo)method);
            }
            else if (method.IsFinal || !method.IsVirtual)
            {
                ILGeneratorExtensions.CallMethod(generator, (MethodInfo)method);
            }
            Type type = method.IsConstructor ? method.DeclaringType : ((MethodInfo)method).ReturnType;

            if (type != typeof(void))
            {
                ILGeneratorExtensions.BoxIfNeeded(generator, type);
            }
            else
            {
                generator.Emit(OpCodes.Ldnull);
            }
            ILGeneratorExtensions.Return(generator);
        }