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


C# MethodBuilder.GetILGenerator方法代码示例

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


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

示例1: Gen

 public override void Gen(TypeBuilder program, MethodBuilder method)
 {
     AstNode left = this.child;
     AstNode right = left.sibling;
     left.Gen(program, method);
     right.Gen(program, method);
     if (this.symbol == "+") {
         method.GetILGenerator().EmitCall(OpCodes.Callvirt, typeof(TypeBase).GetMethod("Add"), new Type[] { typeof(TypeBase) });
     } else if (this.symbol == "-") {
         method.GetILGenerator().EmitCall(OpCodes.Callvirt,typeof(TypeBase).GetMethod("Minus"), new Type[] { typeof(TypeBase) });
     }
 }
开发者ID:crazyender,项目名称:plang,代码行数:12,代码来源:BuildinFunction.cs

示例2: Gen

 public override void Gen(TypeBuilder program, MethodBuilder method)
 {
     EnviromentNode envNode = EnviromentList.Instance.LoopupSymbol(this.symbol);
     AstNode right = this.child;
     right.Gen(program, method);
     if (envNode.IsGlobal) {
         envNode.field = program.DefineField(this.symbol, typeof(TypeBase), System.Reflection.FieldAttributes.Private | System.Reflection.FieldAttributes.Static);
         method.GetILGenerator().Emit(OpCodes.Stsfld, envNode.field);
     } else {
         envNode.local = method.GetILGenerator().DeclareLocal(typeof(TypeBase));
         method.GetILGenerator().Emit(OpCodes.Stloc, envNode.local);
     }
 }
开发者ID:crazyender,项目名称:plang,代码行数:13,代码来源:Sentense.cs

示例3: Gen

 public override void Gen(TypeBuilder program, MethodBuilder method)
 {
     DoGen(program, method);
     // then push a FunctionType value
     EnviromentNode envNode = this.localenv == null ?
         EnviromentList.Instance.LookupLocal(this.symbol) :
         this.localenv.LookupLocal(this.symbol);
     var tmp = method.GetILGenerator().DeclareLocal(typeof(TypeBase));
     method.GetILGenerator().Emit(OpCodes.Ldstr, this.symbol);
     method.GetILGenerator().Emit(OpCodes.Newobj, typeof(FunctionType).GetConstructor(new Type[] { typeof(string) }));
     method.GetILGenerator().Emit(OpCodes.Stloc, tmp);
     SetupClosure(method, envNode.method, envNode.ParamCount, tmp);
     method.GetILGenerator().Emit(OpCodes.Ldloc, tmp);
 }
开发者ID:crazyender,项目名称:plang,代码行数:14,代码来源:Lambda.cs

示例4: Emit

        public void Emit(CompilerErrorCollection errors, MethodBuilder m)
        {
            //Set the parameters
            //ParameterBuilder[] parms = new ParameterInfo[args.Length];
            for(int i = 0; i < args.Length; i++)
                m.DefineParameter(i + 1, ParameterAttributes.None, args[i].Name);

            ILGenerator gen = m.GetILGenerator();

            //Define the IT variable
            LocalRef it = locals["IT"] as LocalRef;
            DefineLocal(gen, it);

            statements.Process(this, errors, gen);

            statements.Emit(this, gen);

            //Cast the IT variable to our return type and return it
            if (m.ReturnType != typeof(void))
            {
                gen.Emit(OpCodes.Ldloc, it.Local);
                Expression.EmitCast(gen, it.Type, m.ReturnType);
            }
            gen.Emit(OpCodes.Ret);
        }
开发者ID:unycorn,项目名称:lolcode-dot-net,代码行数:25,代码来源:Program.cs

示例5: CreateMethodBuilder

 private void CreateMethodBuilder()
 {
     methodBuilder = typeBuilder.DefineMethod(
         "DynamicMethod", MethodAttributes.Public | MethodAttributes.Static, typeof(object), new Type[] { typeof(object), typeof(object[]) });
     methodBuilder.InitLocals = true;
     ilGenerator = methodBuilder.GetILGenerator();
 }
开发者ID:seesharper,项目名称:LightProxy,代码行数:7,代码来源:MethodBuilderMethodSkeleton.cs

示例6: CreateContinueMethod

        private void CreateContinueMethod(MethodInfo method, MethodBuilder continueMethod, int position, Type[] parameters, int count)
        {
            var generator = continueMethod.GetILGenerator();

            // Store array in temp0
            generator.DeclareLocal(typeof (object[]));
            generator.LoadArgument(1);
            generator.StashTemporaryVariable(0);

            // Push backing object onto the stack
            generator.LoadField(backingObject);

            // Push each of the arguments passed in onto the stack
            for (int i = 0; i < count; i++)
            {
                generator.LoadTemporaryVariable(0);
                generator.LoadInteger(i);
                generator.Emit(OpCodes.Ldelem_Ref);
                generator.MaybeUnBox(parameters[i]);
            }

            // Delegate to backing object
            generator.Execute(method);

            // Convert the returned value to an object
            if (method.ReturnType == typeof(void))
                generator.LoadNull();
            else
                generator.MaybeBox(method.ReturnType);

            // Return
            generator.Emit(OpCodes.Ret);
        }
开发者ID:gja,项目名称:LightProxy,代码行数:33,代码来源:ProxyBuilder.cs

示例7: CreateMethodBuilder

 private void CreateMethodBuilder(Type returnType, Type[] parameterTypes)
 {
     methodBuilder = typeBuilder.DefineMethod(
         "DynamicMethod", MethodAttributes.Public | MethodAttributes.Static, returnType, parameterTypes);
     methodBuilder.InitLocals = true;
     emitter = new Emitter(methodBuilder.GetILGenerator(), parameterTypes);
 }
开发者ID:vitamink,项目名称:LightInject,代码行数:7,代码来源:MethodBuilderMethodSkeleton.cs

示例8: EmitMethodBody

		private static void EmitMethodBody (MethodBuilder methodBuilder, MethodInfo methodInfo, String message)
		{
			Type returnType = methodInfo.ReturnType;
			ILGenerator generator = methodBuilder.GetILGenerator ();
			ParameterInfo[] parameterInfos = methodInfo.GetParameters ();

			if (returnType == typeof(void)) {
				MethodInfo sendMessageInvoker = EmitInfos.OBJECTIVECRUNTIME_SENDMESSAGE_VOID_ARGS;

				// Makes the actual call
				generator.Emit (OpCodes.Ldarg_0);
				generator.Emit (OpCodes.Ldstr, message);
				EmitParametersAsArrayOnStack (generator, parameterInfos);
				generator.Emit (OpCodes.Call, sendMessageInvoker);

				generator.Emit (OpCodes.Ret);
			} else {
				MethodInfo sendMessageInvoker = EmitInfos.OBJECTIVECRUNTIME_SENDMESSAGE_ARGS_GENERIC.MakeGenericMethod (returnType);

				// Makes the actual call
				generator.Emit (OpCodes.Ldarg_0);
				generator.Emit (OpCodes.Ldstr, message);
				EmitParametersAsArrayOnStack (generator, parameterInfos);
				generator.Emit (OpCodes.Call, sendMessageInvoker);

				generator.Emit (OpCodes.Ret);
			}
		}
开发者ID:Monobjc,项目名称:monobjc,代码行数:28,代码来源:WrapperGenerator.Generation.cs

示例9: PropertyEmitter

		public PropertyEmitter(TypeBuilder owner, string name, Type propertyType, FieldBuilder propertyChangedField) {
			this.owner = owner;
			this.propertyChangedField = propertyChangedField;
			fieldBuilder = owner.DefineField(String.Format("<{0}>", name), propertyType, FieldAttributes.Private);
			getterBuilder = owner.DefineMethod(String.Format("get_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, propertyType, Type.EmptyTypes);
			ILGenerator getterIl = getterBuilder.GetILGenerator();
			getterIl.Emit(OpCodes.Ldarg_0);
			getterIl.Emit(OpCodes.Ldfld, fieldBuilder);
			getterIl.Emit(OpCodes.Ret);
			setterBuilder = owner.DefineMethod(String.Format("set_{0}", name), MethodAttributes.Public|MethodAttributes.Virtual|MethodAttributes.HideBySig|MethodAttributes.SpecialName, typeof(void), new[] {propertyType});
			ILGenerator setterIl = setterBuilder.GetILGenerator();
			setterIl.Emit(OpCodes.Ldarg_0);
			setterIl.Emit(OpCodes.Ldarg_1);
			setterIl.Emit(OpCodes.Stfld, fieldBuilder);
			if (propertyChangedField != null) {
				setterIl.Emit(OpCodes.Ldarg_0);
				setterIl.Emit(OpCodes.Dup);
				setterIl.Emit(OpCodes.Ldfld, propertyChangedField);
				setterIl.Emit(OpCodes.Ldstr, name);
				setterIl.Emit(OpCodes.Call, proxyBase_NotifyPropertyChanged);
			}
			setterIl.Emit(OpCodes.Ret);
			propertyBuilder = owner.DefineProperty(name, PropertyAttributes.None, propertyType, null);
			propertyBuilder.SetGetMethod(getterBuilder);
			propertyBuilder.SetSetMethod(setterBuilder);
		}
开发者ID:NicoGBN,项目名称:AutoMapper,代码行数:26,代码来源:PropertyEmitter.cs

示例10: EmitEmptyImplementation

 private static void EmitEmptyImplementation( MethodBuilder vM, Type returnType, ParameterInfo[] parameters )
 {
     ILGenerator gVM = vM.GetILGenerator();
     for( int i = 0; i < parameters.Length; ++i )
     {
         // DefineParameter use 0 for the return parameter.
         ParameterInfo param = parameters[i];
         vM.DefineParameter( i + 1, param.Attributes, param.Name );
         if( param.IsOut )
         {
             Debug.Assert( param.ParameterType.IsByRef, "'Out' is just an attribute on 'by ref' parameters (unfortunate for covariance support)." );
             gVM.StoreDefaultValueForOutParameter( param );
         }
     }
     if( returnType != typeof( void ) )
     {
         if( returnType.GetTypeInfo().IsValueType )
         {
             LocalBuilder retValue = gVM.DeclareLocal( returnType );
             gVM.Emit( OpCodes.Ldloca_S, retValue.LocalIndex );
             gVM.Emit( OpCodes.Initobj, returnType );
             gVM.LdLoc( retValue );
         }
         else
         {
             gVM.Emit( OpCodes.Ldnull );
         }
     }
     gVM.Emit( OpCodes.Ret );
 }
开发者ID:Invenietis,项目名称:ck-core,代码行数:30,代码来源:EmitHelper.cs

示例11: SetUp

	protected void SetUp () {
		AssemblyName assemblyName = new AssemblyName();
		assemblyName.Name = GetType().FullName;

		AssemblyBuilder assembly 
			= Thread.GetDomain().DefineDynamicAssembly(
				assemblyName, AssemblyBuilderAccess.Run);

		module = assembly.DefineDynamicModule("module1");
		
	    tb = module.DefineType("class1", 
							   TypeAttributes.Public);

		eb = tb.DefineEvent ("event1", EventAttributes.None, typeof (AnEvent));
		mb = 
			tb.DefineMethod ("OnAnEvent",
							 MethodAttributes.Public, typeof (void),
							 new Type [] { typeof (AnEvent) });
		ILGenerator ilgen = mb.GetILGenerator();
		ilgen.Emit (OpCodes.Ret);

		// These two are required
		eb.SetAddOnMethod (mb);
		eb.SetRemoveOnMethod (mb);
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:25,代码来源:EventBuilderTest.cs

示例12: CreateDynamicMethod

		public void CreateDynamicMethod()
		{
#if SAVE_ASSEMBLY
			if (_assemblyBuilder == null)
			{
				AssemblyName assemblyName = new AssemblyName("ExpressionAssembly");
				_assemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.RunAndSave, "I:\\Trash");
				_moduleBuilder = _assemblyBuilder.DefineDynamicModule("ExpressionModule", "ExpressionModule.module");
			}

			string typeName = String.Format("Expression{0}", _typeCount);
			_typeCount++;

			_typeBuilder = _moduleBuilder.DefineType(typeName, TypeAttributes.Class | TypeAttributes.Public);
			
			FieldBuilder filedBuilder = _typeBuilder.DefineField("Source", typeof(string), FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
			filedBuilder.SetConstant(_source);

			_methodBuilder = _typeBuilder.DefineMethod("Evaluate", MethodAttributes.Public | MethodAttributes.Static, typeof(object), new Type[] { typeof(object[]) });
			_ilGenerator = _methodBuilder.GetILGenerator();
#else
			_dynamicMethod = new DynamicMethod("Expression", typeof(object), new Type[] { typeof(object[]) }, GetType().Module);
			_ilGenerator = _dynamicMethod.GetILGenerator();
#endif
		}
开发者ID:chenzuo,项目名称:nquery,代码行数:25,代码来源:ILEmitContext.cs

示例13: Gen

 public override void Gen(TypeBuilder program, MethodBuilder method)
 {
     AstNode left = this.child;
     AstNode right = left.sibling;
     left.Gen(program, method);
     right.Gen(program, method);
     method.GetILGenerator().EmitCall(OpCodes.Callvirt, typeof(TypeBase).GetMethod("Equal"), new Type[] { typeof(TypeBase) });
 }
开发者ID:crazyender,项目名称:plang,代码行数:8,代码来源:Condition.cs

示例14: BeginMethod

        internal void BeginMethod(Type returnType, MethodBuilderInfo methodBuilderInfo, Type[] argTypes, string[] argNames, MethodAttributes methodAttributes)
        {
#if DEBUG
            methodBuilderInfo.Validate(returnType, argTypes, methodAttributes);
#endif
            _methodBuilder = methodBuilderInfo.MethodBuilder;
            _ilGen = _methodBuilder.GetILGenerator();
            InitILGeneration(argTypes, argNames, (_methodBuilder.Attributes & MethodAttributes.Static) == MethodAttributes.Static);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:CodeGenerator.cs

示例15: EmitEqualsObj

 private void EmitEqualsObj(TypeBuilder typeBuilder, MethodBuilder method, MethodBuilder typedEqualsMethoed)
 {
     ILGenerator iLGenerator = method.GetILGenerator();
     iLGenerator.Emit(OpCodes.Ldarg_0);
     iLGenerator.Emit(OpCodes.Ldarg_1);
     iLGenerator.Emit(OpCodes.Isinst, typeBuilder);
     iLGenerator.EmitCall(OpCodes.Call, typedEqualsMethoed, null);
     iLGenerator.Emit(OpCodes.Ret);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:9,代码来源:AnonymousTypeEmitter.cs


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