当前位置: 首页>>代码示例>>C#>>正文


C# ILGenerator.EmitCall方法代码示例

本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitCall方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitCall方法的具体用法?C# ILGenerator.EmitCall怎么用?C# ILGenerator.EmitCall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.Emit.ILGenerator的用法示例。


在下文中一共展示了ILGenerator.EmitCall方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmitCallMethod

 private static void EmitCallMethod(ILGenerator il, MethodInfo methodInfo)
 {
     if (methodInfo.IsStatic)
         il.EmitCall(OpCodes.Call, methodInfo, null);
     else
         il.EmitCall(OpCodes.Callvirt, methodInfo, null);
 }
开发者ID:Cussa,项目名称:simple-commons,代码行数:7,代码来源:DelegateFactory.cs

示例2: InvokeMethod

 /// <summary>
 ///     Generates method invocation code.
 /// </summary>
 /// <param name="il">IL generator to use.</param>
 /// <param name="isStatic">Flag specifying whether method is static.</param>
 /// <param name="isValueType">Flag specifying whether method is on the value type.</param>
 /// <param name="method">Method to invoke.</param>
 protected static void InvokeMethod(ILGenerator il, bool isStatic, bool isValueType, MethodInfo method)
 {
     if (isStatic || isValueType)
     {
         il.EmitCall(OpCodes.Call, method, null);
     }
     else
     {
         il.EmitCall(OpCodes.Callvirt, method, null);
     }
 }
开发者ID:kog,项目名称:Solenoid-Expressions,代码行数:18,代码来源:BaseDynamicMember.cs

示例3: BuildAssembly

 public override void BuildAssembly( ILGenerator il )
 {
     System.Type[] types = { typeof(String) };
     if (Format != null && Format.Equals("/")) {
         il.Emit(OpCodes.Ldstr, "\n");
         il.EmitCall(OpCodes.Call, typeof(openABAP.Runtime.Runtime).GetMethod("Write", types), null);
     }
     //push formatted string of output value to stack
     this.Value.PushFormattedString(il);
     il.EmitCall(OpCodes.Call, typeof(openABAP.Runtime.Runtime).GetMethod("Write", types), null);
 }
开发者ID:bi-tm,项目名称:openABAP,代码行数:11,代码来源:Write.cs

示例4: GenerateSerializerSwitch

        public static void GenerateSerializerSwitch(CodeGenContext ctx, ILGenerator il, IDictionary<Type, TypeData> map)
        {
            // arg0: Stream, arg1: object

            var idLocal = il.DeclareLocal(typeof(ushort));

            // get TypeID from object's Type
            var getTypeIDMethod = typeof(Serializer).GetMethod("GetTypeID", BindingFlags.NonPublic | BindingFlags.Static, null, new Type[] { typeof(object) }, null);
            il.Emit(OpCodes.Ldarg_1);
            il.EmitCall(OpCodes.Call, getTypeIDMethod, null);
            il.Emit(OpCodes.Stloc_S, idLocal);

            // write typeID
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldloc_S, idLocal);
            il.EmitCall(OpCodes.Call, ctx.GetWriterMethodInfo(typeof(ushort)), null);

            // +1 for 0 (null)
            var jumpTable = new Label[map.Count + 1];
            jumpTable[0] = il.DefineLabel();
            foreach (var kvp in map)
                jumpTable[kvp.Value.TypeID] = il.DefineLabel();

            il.Emit(OpCodes.Ldloc_S, idLocal);
            il.Emit(OpCodes.Switch, jumpTable);

            ConstructorInfo exceptionCtor = typeof(Exception).GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
            il.Emit(OpCodes.Newobj, exceptionCtor);
            il.Emit(OpCodes.Throw);

            /* null case */
            il.MarkLabel(jumpTable[0]);
            il.Emit(OpCodes.Ret);

            /* cases for types */
            foreach (var kvp in map)
            {
                var type = kvp.Key;
                var data = kvp.Value;

                il.MarkLabel(jumpTable[data.TypeID]);

                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldarg_1);
                il.Emit(type.IsValueType ? OpCodes.Unbox_Any : OpCodes.Castclass, type);

                il.EmitCall(OpCodes.Call, data.WriterMethodInfo, null);

                il.Emit(OpCodes.Ret);
            }
        }
开发者ID:NelsonDrueding,项目名称:netserializer,代码行数:51,代码来源:SerializerCodegen.cs

示例5: Emit

 /// <summary>
 /// 写入类型转换的指令。
 /// </summary>
 /// <param name="generator">IL 的指令生成器。</param>
 /// <param name="inputType">要转换的对象的类型。</param>
 /// <param name="outputType">要将输入对象转换到的类型。</param>
 /// <param name="isChecked">是否执行溢出检查。</param>
 public override void Emit(ILGenerator generator, Type inputType, Type outputType, bool isChecked)
 {
     MethodInfo method = converter.Method;
     if (method.IsStatic && method.GetParametersNoCopy().Length == 1)
     {
         // 没有闭包的静态方法可以直接调用。
         generator.EmitCall(method);
     }
     else
     {
         // 有闭包的静态方法,或实例方法,其参数不能直接写入 IL,因此直接调用 Convert 的 ChangeType 方法。
         generator.EmitCall(changeType.MakeGenericMethod(inputType, outputType));
     }
 }
开发者ID:GISwilson,项目名称:Cyjb,代码行数:21,代码来源:DelegateConversion.cs

示例6: WriteGetter

        private static void WriteGetter(ILGenerator il, Type type, PropertyInfo[] props, FieldInfo[] fields, bool isStatic)
        {
            var loc = type.IsValueType ? il.DeclareLocal(type) : null;
            OpCode propName = isStatic ? OpCodes.Ldarg_1 : OpCodes.Ldarg_2, target = isStatic ? OpCodes.Ldarg_0 : OpCodes.Ldarg_1;
            foreach (var prop in props)
            {
                MethodInfo getter;
                if (prop.GetIndexParameters().Length != 0 || !prop.CanRead || (getter = prop.GetGetMethod(false)) == null) continue;

                var next = il.DefineLabel();
                il.Emit(propName);
                il.Emit(OpCodes.Ldstr, prop.Name);
                il.EmitCall(OpCodes.Call, strinqEquals, null);
                il.Emit(OpCodes.Brfalse_S, next);
                // match:
                il.Emit(target);
                Cast(il, type, loc);
                il.EmitCall(type.IsValueType ? OpCodes.Call : OpCodes.Callvirt, getter, null);
                if (prop.PropertyType.IsValueType)
                {
                    il.Emit(OpCodes.Box, prop.PropertyType);
                }
                il.Emit(OpCodes.Ret);
                // not match:
                il.MarkLabel(next);
            }
            foreach (var field in fields)
            {
                var next = il.DefineLabel();
                il.Emit(propName);
                il.Emit(OpCodes.Ldstr, field.Name);
                il.EmitCall(OpCodes.Call, strinqEquals, null);
                il.Emit(OpCodes.Brfalse_S, next);
                // match:
                il.Emit(target);
                Cast(il, type, loc);
                il.Emit(OpCodes.Ldfld, field);
                if (field.FieldType.IsValueType)
                {
                    il.Emit(OpCodes.Box, field.FieldType);
                }
                il.Emit(OpCodes.Ret);
                // not match:
                il.MarkLabel(next);
            }
            il.Emit(OpCodes.Ldstr, "name");
            il.Emit(OpCodes.Newobj, typeof(ArgumentOutOfRangeException).GetConstructor(new Type[] { typeof(string) }));
            il.Emit(OpCodes.Throw);
        }
开发者ID:VictorTomaili,项目名称:Sanity,代码行数:49,代码来源:TypeAccessor.cs

示例7: EmitParameterResolution

        /// <summary>
        /// 
        /// </summary>
        /// <param name="il"></param>
        /// <param name="paramAttr"></param>
        /// <param name="parameterType"></param>
        public override void EmitParameterResolution(ILGenerator il, ParameterAttribute paramAttr, Type parameterType)
        {
            ProviderDependencyAttribute attr = (ProviderDependencyAttribute) paramAttr;
            MethodInfo getHeadOfChain = GetPropertyGetter<IBuilderContext>("HeadOfChain", typeof (IBuilderStrategy));
            MethodInfo buildUp = GetMethodInfo<IBuilderStrategy>("BuildUp",
                                                                 typeof (IBuilderContext), typeof (Type), typeof (object),
                                                                 typeof (string));

            PropertyInfo prop =
                attr.ProviderHostType.GetProperty(attr.ProviderGetterProperty, BindingFlags.Static | BindingFlags.Public);
            if (prop == null)
            {
                throw new ArgumentException();
            }

            MethodInfo propInvoker = prop.GetGetMethod();
            if (propInvoker == null)
            {
                throw new ArgumentException();
            }
            Guid.NewGuid();
            MethodInfo newGuidMethod = typeof (Guid).GetMethod("NewGuid");
            MethodInfo guidToStringMethod = typeof (Guid).GetMethod("ToString", new Type[] {});
            if ((newGuidMethod == null) || (guidToStringMethod == null))
            {
                throw new ArgumentException();
            }

            //object value (declaration)
            LocalBuilder valueIndex = il.DeclareLocal(typeof (object));

            //object value = prop.GetGetMethod().Invoke(attr.ProviderHostType, null);
            //value = propInvoker.Invoke(null) (return value remains in the stack)
            il.EmitCall(OpCodes.Call, propInvoker, null);
            il.Emit(OpCodes.Stloc, valueIndex);

            //string id = Guid.NewGuid().ToString();
            //il.Emit(OpCodes.Ldtoken, typeof(Guid));
            //il.EmitCall(OpCodes.Call, newGuidMethod, null);
            //il.EmitCall(OpCodes.Call, guidToStringMethod, null);
            //il.Emit(OpCodes.Stloc, idIndex);

            // Get the head of the context chain
            il.Emit(OpCodes.Ldarg_0); // Get context onto the stack
            il.EmitCall(OpCodes.Callvirt, getHeadOfChain, null); // Now head of chain is on the stack

            // Build up parameters to the BuildUp call - context, type, existing, id
            il.Emit(OpCodes.Ldarg_0); // Push context onto stack
            EmitLoadType(il, parameterType);

            // Existing object is value
            il.Emit(OpCodes.Ldloc, valueIndex);

            // And the id
            //il.Emit(OpCodes.Ldloc,idIndex);
            il.Emit(OpCodes.Ldarg_3);

            // Call buildup on head of the chain
            il.EmitCall(OpCodes.Callvirt, buildUp, null);
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:66,代码来源:ProviderDependencyParameterResolver.cs

示例8: OnInvokeEnd

        /// <summary>
        /// Implements code for end invocations.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="interfaceType"></param>
        /// <param name="generator"></param>
        /// <param name="interfaceMethod"></param>
        protected override void OnInvokeEnd(TypeBuilder type, Type interfaceType, ILGenerator generator, MethodInfo interfaceMethod)
        {
            var skip = interfaceMethod.GetCustomAttributes(typeof(SkipProbeAttribute), false).OfType<SkipProbeAttribute>().FirstOrDefault();
            if ( skip != null && (skip.SkipActions & ProbeActions.End) == ProbeActions.End)
                return;

            var probeType = typeof(IMethodCallProbe<>).MakeGenericType(interfaceType);
            var endInvoke = probeType.GetMethod("OnEndInvoke");
            generator.Emit(OpCodes.Ldarg_0);
            generator.Emit(OpCodes.Ldfld, probeField());
            generator.Emit(OpCodes.Ldtoken, interfaceMethod);
            generator.EmitCall(OpCodes.Call, typeof(MethodBase).GetMethod("GetMethodFromHandle", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(RuntimeMethodHandle) }, null), null);
            generator.Emit(OpCodes.Ldarg_0);
            generator.EmitCall(OpCodes.Callvirt, endInvoke, null);

            base.OnInvokeEnd(type, interfaceType, generator, interfaceMethod);
        }
开发者ID:GeirGrusom,项目名称:PlatformInvoker,代码行数:24,代码来源:ProbingMethodCallWrapper.cs

示例9: EmitIL

 public void EmitIL(ILGenerator body, FieldInfo tape, FieldInfo ptr)
 {
     body.Emit(OpCodes.Ldsfld, tape);
     body.Emit(OpCodes.Ldsfld, ptr);
     body.EmitCall(OpCodes.Call,
         typeof(Console).GetMethod("Read", new Type[0]), null);
     body.Emit(OpCodes.Stelem_I4);
 }
开发者ID:paf31,项目名称:BF,代码行数:8,代码来源:In.cs

示例10: EmitParameterResolution

        /// <summary>
        /// 
        /// </summary>
        /// <param name="il"></param>
        /// <param name="paramAttr"></param>
        /// <param name="parameterType"></param>
        public override void EmitParameterResolution(ILGenerator il, ParameterAttribute paramAttr, Type parameterType)
        {
            ServiceDependencyAttribute attr = (ServiceDependencyAttribute) paramAttr;
            MethodInfo getLocator = GetPropertyGetter<IBuilderContext>("Locator", typeof (IReadWriteLocator));
            MethodInfo getFromLocator = ObtainGetFromLocatorMethod();
            MethodInfo getServices =
                GetPropertyGetter<CompositionContainer>("Services", typeof (IServiceCollection));
            MethodInfo getFromServices = GetMethodInfo<IServiceCollection>("Get", typeof (Type), typeof (bool));
            ConstructorInfo newDependencyKey =
                GetConstructor<DependencyResolutionLocatorKey>(typeof (Type), typeof (string));

            // context.get_Locator
            il.Emit(OpCodes.Ldarg_0);
            il.EmitCall(OpCodes.Callvirt, getLocator, null);

            // new DependencyResolutionContainer(typeof(CompositionContainer), null)
            EmitLoadType(il, typeof (CompositionContainer));
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Newobj, newDependencyKey);
            // locator.Get(key)
            il.EmitCall(OpCodes.Callvirt, getFromLocator, null);
            il.Emit(OpCodes.Castclass, typeof (CompositionContainer));

            // container.get_Services
            il.EmitCall(OpCodes.Callvirt, getServices, null);

            if (attr.Type != null)
            {
                EmitLoadType(il, attr.Type);
            }
            else
            {
                EmitLoadType(il, parameterType);
            }

            if (attr.Required)
            {
                il.Emit(OpCodes.Ldc_I4_1);
            }
            else
            {
                il.Emit(OpCodes.Ldc_I4_0);
            }
            il.EmitCall(OpCodes.Callvirt, getFromServices, null);
        }
开发者ID:riseandcode,项目名称:open-wscf-2010,代码行数:51,代码来源:ServiceDependencyParameterResolver.cs

示例11: EmitIL

 public void EmitIL(ILGenerator body, FieldInfo tape, FieldInfo ptr)
 {
     body.Emit(OpCodes.Ldsfld, tape);
     body.Emit(OpCodes.Ldsfld, ptr);
     body.Emit(OpCodes.Ldelem_I4);
     body.Emit(OpCodes.Conv_U2);
     body.EmitCall(OpCodes.Call,
         typeof(Console).GetMethod("Write", new Type[] { typeof(char) }), null);
 }
开发者ID:paf31,项目名称:BF,代码行数:9,代码来源:Out.cs

示例12: PushValue

 public void PushValue(ILGenerator il)
 {
     System.Type[] types = { typeof(string), typeof(openABAP.Runtime.IfValue) };
     MethodInfo mi = typeof(openABAP.Runtime.IfValue).GetMethod("Calculate", types);
     this.LeftChild.PushValue(il);
     il.Emit(OpCodes.Ldstr, this.Operator);
     this.RightChild.PushValue(il);
     il.EmitCall(OpCodes.Callvirt, mi, null);
 }
开发者ID:bi-tm,项目名称:openABAP,代码行数:9,代码来源:Expression.cs

示例13: BuildAssembly

 public override void BuildAssembly( ILGenerator il )
 {
     System.Type[] types = {typeof(openABAP.Runtime.IfValue)};
     System.Type t = this.Target.GetRuntimeType();
     MethodInfo mi = t.GetMethod("Set", types);
     this.Target.PushValue( il );
     this.Expression.PushValue( il );
     il.EmitCall (OpCodes.Callvirt, mi, null);
 }
开发者ID:bi-tm,项目名称:openABAP,代码行数:9,代码来源:Compute.cs

示例14: Emit

 /// <summary>
 /// 写入类型转换的 IL 指令。
 /// </summary>
 /// <param name="generator">IL 的指令生成器。</param>
 /// <param name="inputType">要转换的对象的类型。</param>
 /// <param name="outputType">要将输入对象转换到的类型。</param>
 /// <param name="isChecked">是否执行溢出检查。</param>
 public override void Emit(ILGenerator generator, Type inputType, Type outputType, bool isChecked)
 {
     Contract.Assume(inputType.IsNullable());
     Type inputUnderlyingType = Nullable.GetUnderlyingType(inputType);
     generator.EmitCall(inputType.GetMethod("get_Value"));
     if (inputUnderlyingType != outputType)
     {
         Conversion conversion = ConversionFactory.GetConversion(inputUnderlyingType, outputType);
         Contract.Assume(conversion != null);
         conversion.Emit(generator, inputUnderlyingType, outputType, isChecked);
     }
 }
开发者ID:GISwilson,项目名称:Cyjb,代码行数:19,代码来源:FromNullableConversion.cs

示例15: Call

        public static void Call(ILGenerator gen, MethodInfo method)
        {
            if (gen == null)
            {
                throw new ArgumentNullException("gen");
            }

            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            if (method.IsFinal || !method.IsVirtual)
            {
                gen.EmitCall(OpCodes.Call, method, null);
            }
            else
            {
                gen.EmitCall(OpCodes.Callvirt, method, null);
            }
        }
开发者ID:Oman,项目名称:Maleos,代码行数:21,代码来源:EmitUtils.cs


注:本文中的System.Reflection.Emit.ILGenerator.EmitCall方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。