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


C# Emit.ILGenerator类代码示例

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


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

示例1: EmitIL

 public void EmitIL(ILGenerator body, FieldInfo tape, FieldInfo ptr)
 {
     body.Emit(OpCodes.Ldsfld, ptr);
     body.Emit(OpCodes.Ldc_I4_1);
     body.Emit(OpCodes.Sub);
     body.Emit(OpCodes.Stsfld, ptr);
 }
开发者ID:paf31,项目名称:BF,代码行数:7,代码来源:DecrPtr.cs

示例2: FleeILGenerator

		public FleeILGenerator(ILGenerator ilg, int startLength = 0, bool isTemp = false)
		{
			MyILGenerator = ilg;
			MyTempLocals = new Dictionary<Type, LocalBuilder>();
			MyIsTemp = isTemp;
			MyLength = startLength;
		}
开发者ID:netgrim,项目名称:FleeSharp,代码行数:7,代码来源:FleeILGenerator.cs

示例3: ArgumentReferenceEmitter

        internal ArgumentReferenceEmitter(IdentifierExpression identifierExpression, ParameterDefinition parameterDefinition, ILGenerator ilGenerator, IOpCodeIndexer instructionsIndexer)
            : base(ilGenerator, instructionsIndexer) {

            _parameterDefinition = parameterDefinition;
            _identifierExpression = identifierExpression;
            Type = parameterDefinition.ParameterType.GetActualType();
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:ArgumentReferenceEmitter.cs

示例4: EmitLoadIndirectOpCodeForType

		/// <summary>
		/// Emits a load indirect opcode of the appropriate type for a value or object reference.
		/// Pops a pointer off the evaluation stack, dereferences it and loads
		/// a value of the specified type.
		/// </summary>
		/// <param name="gen"></param>
		/// <param name="type"></param>
		public static void EmitLoadIndirectOpCodeForType(ILGenerator gen, Type type)
		{
			if (type.IsEnum)
			{
				EmitLoadIndirectOpCodeForType(gen, GetUnderlyingTypeOfEnum(type));
				return;
			}

			if (type.IsByRef)
			{
				throw new NotSupportedException("Cannot load ByRef values");
			}
			else if (type.IsPrimitive)
			{
				OpCode opCode = LdindOpCodesDictionary.Instance[type];

				if (Object.ReferenceEquals(opCode, LdindOpCodesDictionary.EmptyOpCode))
				{
					throw new ArgumentException("Type " + type + " could not be converted to a OpCode");
				}

				gen.Emit(opCode);
			}
			else if (type.IsValueType)
			{
				gen.Emit(OpCodes.Ldobj, type);
			}
			else
			{
				gen.Emit(OpCodes.Ldind_Ref);
			}
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:39,代码来源:OpCodeUtil.cs

示例5: EmitToObjectConversion

 /// <summary>
 /// Emits a conversion to type object for the value on the stack.
 /// </summary>
 /// <param name="generator">The code generator to use.</param>
 /// <param name="sourceType">The type of value on the stack.</param>
 public static void EmitToObjectConversion(ILGenerator generator, Type sourceType)
 {
     if (sourceType.IsValueType)
     {
         generator.Emit(OpCodes.Box, sourceType);
     }
 }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:12,代码来源:DynamicMethodUtility.cs

示例6: Emit

		public override void Emit(IEasyMember member, ILGenerator gen)
		{
			LocalBuilder local = gen.DeclareLocal( typeof(object[]) );
			gen.Emit(OpCodes.Ldc_I4, _args.Length);
			gen.Emit(OpCodes.Newarr, typeof(object));
			gen.Emit(OpCodes.Stloc, local);
			
			for(int i=0; i < _args.Length; i++)
			{
				gen.Emit(OpCodes.Ldloc, local);
				gen.Emit(OpCodes.Ldc_I4, i);

				TypeReference reference = _args[i];

				ArgumentsUtil.EmitLoadOwnerAndReference(reference, gen);

				if (reference.Type.IsByRef)
				{
					throw new NotSupportedException();
				}

				if (reference.Type.IsValueType)
				{
					gen.Emit(OpCodes.Box, reference.Type.UnderlyingSystemType);
				}
				
				gen.Emit(OpCodes.Stelem_Ref);
			}

			gen.Emit(OpCodes.Ldloc, local);
		}
开发者ID:ralescano,项目名称:castle,代码行数:31,代码来源:ReferencesToObjectArrayExpression.cs

示例7: Generate

        public override void Generate(ILGenerator generator, Symbols symbols)
        {
            //Save the previous variables
            var currentVariables = new List<string>();
            foreach (var item in symbols.Variables)
            {
                currentVariables.Add(item.Key);
                generator.Emit(OpCodes.Ldsfld, symbols.Variables[item.Key]);
            }

            DeclarationBlock.Generate(generator, symbols);
            InstructionsBlock.Generate(generator, symbols);

            LocalBuilder returnValue = null;
            if (InstructionsBlock.ExpressionType.Type != TypesEnumeration.Void)
            {
                returnValue = generator.DeclareLocal(symbols.GetRealType(InstructionsBlock.ExpressionType.ILName));
                generator.Emit(OpCodes.Stloc, returnValue);
            }

            currentVariables.Reverse();
            //load in the variables it's previous values
            currentVariables.ForEach(x => generator.Emit(OpCodes.Stsfld, symbols.Variables[x]));
            if (InstructionsBlock.ExpressionType.Type != TypesEnumeration.Void)
                generator.Emit(OpCodes.Ldloc, returnValue);
        }
开发者ID:hansel0691,项目名称:Tiger,代码行数:26,代码来源:LetInEndNode.cs

示例8: CopyLabels

 void CopyLabels(ILGenerator Gen, int i, Dictionary<int, Label> LateLabels)
 {
     if(!LateLabels.ContainsKey(i)) return;
     
     Gen.MarkLabel(LateLabels[i]);
     LateLabels.Remove(i);
 }
开发者ID:BillTheBest,项目名称:IronAHK,代码行数:7,代码来源:CopyLabels.cs

示例9: AppendWrite

		public override void AppendWrite(ILGenerator generator, MessageField field)
		{
			var done = generator.DefineLabel();
			var tmp = generator.DeclareLocal(typeof(Nullable<>).MakeGenericType(FieldType));

			generator.Emit(OpCodes.Ldloc_0);
			generator.Emit(OpCodes.Call, Property.GetGetMethod());
			generator.Emit(OpCodes.Stloc, tmp.LocalIndex);

			generator.Emit(OpCodes.Ldloca, tmp.LocalIndex);
			generator.Emit(OpCodes.Call, typeof(Nullable<>)
				.MakeGenericType(FieldType)
				.GetProperty("HasValue")
				.GetGetMethod());

			generator.Emit(OpCodes.Brfalse_S, done);

			field.AppendGuard(generator, Property.GetGetMethod(), done);
			field.AppendHeader(generator);

			generator.Emit(OpCodes.Ldloca, tmp.LocalIndex);
			generator.Emit(OpCodes.Call, typeof(Nullable<>)
				.MakeGenericType(FieldType)
				.GetProperty("Value")
				.GetGetMethod());

			field.AppendWriteField(generator);
			generator.Emit(OpCodes.Pop);
			generator.MarkLabel(done);
		}
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:30,代码来源:NullableFieldIO.cs

示例10: 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

示例11: GenerateCode

        public override void GenerateCode(ILGenerator codeGenerator, TypeBuilder typeBuilder, ModuleBuilder moduleBuilder)
        {
            LeftOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);
            RightOperand.GenerateCode(codeGenerator, typeBuilder, moduleBuilder);

            Label endLabel = codeGenerator.DefineLabel();
            Label trueLabel = codeGenerator.DefineLabel();

            if (LeftOperand.ReturnType == StringType.StringInstance)
            {
                codeGenerator.Emit(OpCodes.Call, typeof(String).GetMethod("CompareTo", new Type[] { typeof(string) }));
                codeGenerator.Emit(OpCodes.Ldc_I4_0);
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);
            }
            else
                codeGenerator.Emit(OpCodes.Bne_Un, trueLabel);

            codeGenerator.Emit(OpCodes.Ldc_I4_0);
            codeGenerator.Emit(OpCodes.Br, endLabel);

            codeGenerator.MarkLabel(trueLabel);
            codeGenerator.Emit(OpCodes.Ldc_I4_1);

            codeGenerator.MarkLabel(endLabel);
        }
开发者ID:sandygk,项目名称:Tiger-Compiler,代码行数:25,代码来源:NotEqNode.cs

示例12: TypeLocalPool

 public TypeLocalPool(ILGenerator gen, Type t)
 {
     this.Type = t;
     this.stack = new Stack<LocalBuilder>();
     this.queue = new Queue<LocalBuilder>();
     this.ilgen = gen;
 }
开发者ID:Redflameman0,项目名称:SteamKit2,代码行数:7,代码来源:JITContext.cs

示例13: BuildArguments

        public override LocalBuilder BuildArguments(ILGenerator ilGenerator)
        {
            LocalBuilder propertyLocalBuilder = null;
            FieldBuilder contractFieldBuilder = null;
            LocalBuilder aspectArgLocalBuilder = null;
            ConstructorInfo ctorInterceptionArgs = null;
            AbstractAspectPropertyArgsWeaver methodWeaver = null;

            propertyLocalBuilder = LocalBuilderRepository.Declare(() => {
                return ilGenerator.DeclareLocal(typeof(PropertyInfo));
            });

            ctorInterceptionArgs = ArgumentType.GetConstructors()[0];
            aspectArgLocalBuilder = ilGenerator.DeclareLocal(ArgumentType);
            contractFieldBuilder = WeavingSettings.TypeDefinition.GetFieldBuilder(WeavingSettings.ContractType);
            methodWeaver = new AspectArgsGetPropertyWeaver(Member, propertyLocalBuilder, aspectWeavingSettings);
            methodWeaver.Weave(ilGenerator);
            ilGenerator.EmitLoadArg(0);
            ilGenerator.Emit(OpCodes.Ldfld, contractFieldBuilder);
            ilGenerator.EmitLoadLocal(propertyLocalBuilder);
            ilGenerator.Emit(OpCodes.Ldsfld, BindingsDependency);
            ilGenerator.Emit(OpCodes.Newobj, ctorInterceptionArgs);
            ilGenerator.EmitStoreLocal(aspectArgLocalBuilder);

            return aspectArgLocalBuilder;
        }
开发者ID:sagifogel,项目名称:NCop,代码行数:26,代码来源:TopGetPropertyInterceptionArgumentsWeaver.cs

示例14: AbstractCodeBuilder

		protected AbstractCodeBuilder(ILGenerator generator)
		{
			this.generator = generator;
			stmts = new ArrayList();
			ilmarkers = new ArrayList();
			isEmpty = true;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:7,代码来源:AbstractCodeBuilder.cs

示例15: GenDeserializerBody

        static void GenDeserializerBody(CodeGenContext ctx, Type type, ILGenerator il)
        {
            if (type.IsClass)
            {
                // instantiate empty class
                il.Emit(OpCodes.Ldarg_1);

                var gtfh = typeof(Type).GetMethod("GetTypeFromHandle", BindingFlags.Public | BindingFlags.Static);
                var guo = typeof(System.Runtime.Serialization.FormatterServices).GetMethod("GetUninitializedObject", BindingFlags.Public | BindingFlags.Static);
                il.Emit(OpCodes.Ldtoken, type);
                il.Emit(OpCodes.Call, gtfh);
                il.Emit(OpCodes.Call, guo);
                il.Emit(OpCodes.Castclass, type);

                il.Emit(OpCodes.Stind_Ref);
            }

            var fields = GetFieldInfos(type);

            foreach (var field in fields)
            {
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Ldarg_1);
                if (type.IsClass)
                    il.Emit(OpCodes.Ldind_Ref);
                il.Emit(OpCodes.Ldflda, field);

                GenDeserializerCall(ctx, il, field.FieldType);
            }

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


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