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


C# ILProcessor.Create方法代码示例

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


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

示例1: EmitCodeInit

 private Instruction EmitCodeInit(TypeReference role, Instruction instructionBeforeInit, ILProcessor il)
 {
     var current = instructionBeforeInit;
       current = InsertAfter(il, current, il.Create(OpCodes.Ldarg_0));
       current = InsertAfter(il, current, il.Create(OpCodes.Call, ResolveInitReference(role)));
       return current;
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:7,代码来源:RoleComposer.Initialization.cs

示例2: InterceptMethod

 private void InterceptMethod(ILProcessor processor, TypeReference typeReference, Instruction instruction, string name)
 {
     var typeDefinition = typeReference.Resolve();
     var attributeConstructor = typeDefinition.Methods.First(x => x.Name == ".ctor");
     var attributeMethod = typeDefinition.Methods.First(x => x.Name == name);
     processor.InsertBefore(instruction, processor.Create(OpCodes.Newobj, attributeConstructor));
     processor.InsertBefore(instruction, processor.Create(OpCodes.Call, _getCurrentMethod));
     processor.InsertBefore(instruction, processor.Create(OpCodes.Call, attributeMethod));
 }
开发者ID:AlbertoMonteiro,项目名称:MethodInterceptorAopWithFody,代码行数:9,代码来源:ModuleWeaver.cs

示例3: EmitStateClassCreation

 private Instruction EmitStateClassCreation(TypeReference role, Instruction instructionBeforeCreation, ILProcessor il)
 {
     var current = instructionBeforeCreation;
       var stateClassFieldReference = ResolveStateClassField(role);
       // don't emit this code if the state field and property was not implemented
       // TODO: this needs to be checked before, possibly at the conflict resolution stage
       if (stateClassFieldReference != null) {
     current = InsertAfter(il, current, il.Create(OpCodes.Ldarg_0));
     current = InsertAfter(il, current, il.Create(OpCodes.Newobj, role.ResolveStateClassCtor()));
     current = InsertAfter(il, current, il.Create(OpCodes.Stfld, stateClassFieldReference));
       }
       return current;
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:13,代码来源:RoleComposer.Initialization.cs

示例4: ProcessCachedStaticFieldPattern

		private void ProcessCachedStaticFieldPattern(ILProcessor il, Instruction queryInvocation)
		{
			MethodReference predicateMethod = GetMethodReferenceFromStaticFieldPattern(queryInvocation);
			il.InsertBefore(queryInvocation, il.Create(OpCodes.Ldtoken, predicateMethod));

			// At this point the stack is like this:
			//     runtime method handle, delegate reference, ObjectContainer
			
			il.Replace(queryInvocation,
			               il.Create(OpCodes.Call,
			                             InstantiateGenericMethod(
			                             	_NativeQueryHandler_ExecuteInstrumentedStaticDelegateQuery,
			                             	GetQueryCallExtent(queryInvocation))));
		}
开发者ID:superyfwy,项目名称:db4o,代码行数:14,代码来源:QueryInvocationProcessor.cs

示例5: AddConditionGoto

        private Instruction AddConditionGoto(ILProcessor ilp, Instruction last, Instruction stateMachineStarting)
        {
            var shouldRunSynchronouslyMethod = _engine.GetMethod<Func<ActorCore, bool>> (a => a.ShouldRunSynchronously ());

            var loadThis = ilp.Create (OpCodes.Ldarg_0);
            var loadField = ilp.Create (OpCodes.Ldfld, _actorMixin);
            var callMethod = ilp.Create (OpCodes.Call, shouldRunSynchronouslyMethod);
            var gotoNext = ilp.Create (OpCodes.Brtrue_S, stateMachineStarting);

            ilp.InsertAfter (last, loadThis);
            ilp.InsertAfter (loadThis, loadField);
            ilp.InsertAfter (loadField, callMethod);
            ilp.InsertAfter (callMethod, gotoNext);

            return gotoNext;
        }
开发者ID:JeanSebTr,项目名称:Comedian,代码行数:16,代码来源:AsyncMethodWeaver.cs

示例6: ModifyCallScope

        public void ModifyCallScope(MethodDefinition renamedMethod, MethodDefinition interceptorMethod, ILProcessor il,
            MethodInterceptionScopeType interceptionScope)
        {
            if (interceptionScope == MethodInterceptionScopeType.Deep)
            {
                foreach (var module in Type.Assembly.Definition.Modules)
                {
                    foreach (var type in module.Types.ToList())
                    {
                        if (type.Methods == null || type.Methods.Count == 0) continue;
                        foreach (var method in type.Methods.ToList())
                        {
                            if (Context.Marker.HasMarker(method, Method.MethodMarker)) continue;

                            if (method == null
                                || method.Body == null
                                || method.Body.Instructions == null
                                || method.Body.Instructions.Count() == 0)
                                continue;

                            foreach (var instruction in method.Body.Instructions.ToList())
                            {
                                if (instruction.OpCode == OpCodes.Call && instruction.Operand == renamedMethod)
                                {
                                    var processor = method.Body.GetILProcessor();
                                    processor.InsertAfter(instruction, il.Create(OpCodes.Call, interceptorMethod));
                                    processor.Remove(instruction);
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:fir3pho3nixx,项目名称:cryo-aop,代码行数:34,代码来源:MethodScopingExtension.cs

示例7: ProcessPredicateCreationPattern

		private void ProcessPredicateCreationPattern(ILProcessor il, Instruction queryInvocation)
		{
			MethodReference predicateMethod = GetMethodReferenceFromInlinePredicatePattern(queryInvocation);

			Instruction ldftn = GetNthPrevious(queryInvocation, 2);
			il.InsertBefore(ldftn, il.Create(OpCodes.Dup));

			il.InsertBefore(queryInvocation, il.Create(OpCodes.Ldtoken, predicateMethod));

			// At this point the stack is like this:
			//     runtime method handle, delegate reference, target object, ObjectContainer
			il.Replace(queryInvocation,
			               il.Create(OpCodes.Call,
			                             InstantiateGenericMethod(
			                             	_NativeQueryHandler_ExecuteInstrumentedDelegateQuery,
			                             	GetQueryCallExtent(queryInvocation))));
		}
开发者ID:erdincay,项目名称:db4o,代码行数:17,代码来源:QueryInvocationProcessor.cs

示例8: MethodBodyPatcher

        public MethodBodyPatcher(string methodName, MethodDefinition method)
        {
            _methodName = methodName;
            _methodBody = method.Body;
            _processor = _methodBody.GetILProcessor();

            _realBodyStart = _methodBody.Instructions.First();
            _realBodyEnd = _methodBody.Instructions.Last();

            _markStart1BeforeCreateArgumentsArray = _processor.Create(OpCodes.Nop);
            _markStart2BeforeCreateMethodExecutionArgs = _processor.Create(OpCodes.Nop);
            _markStart3BeforeOnEntryCall = _processor.Create(OpCodes.Nop);
            _markStart4BeforeRealBodyStartExceptionHandler = _processor.Create(OpCodes.Nop);
            _markEnd1NewRealBodyEnd = _processor.Create(OpCodes.Nop);
            _markEnd2BeforeOnExitCall = _processor.Create(OpCodes.Nop);
            _markRetNew = EndsWithThrow ? _processor.Create(OpCodes.Throw) : _processor.Create(OpCodes.Ret);
        }
开发者ID:swestner,项目名称:MethodBoundaryAspect.Fody,代码行数:17,代码来源:MethodBodyPatcher.cs

示例9: ImplementProceed

            protected override void ImplementProceed(MethodDefinition methodInfo, MethodBody methodBody, ILProcessor il, FieldReference methodInfoField, MethodReference proceed, Action<ILProcessor> emitProceedTarget, MethodReference proceedTargetMethod, OpCode proceedOpCode)
            {
                // If T is an interface, then we want to check if target is null; if so, we want to just return the default value
                var targetNotNull = il.Create(OpCodes.Nop);
                EmitProxyFromProceed(il);
                il.Emit(OpCodes.Ldfld, ClassWeaver.Target);  // Load "target" from "this"
                il.Emit(OpCodes.Brtrue, targetNotNull);      // If target is not null, jump below
                CecilExtensions.CreateDefaultMethodImplementation(methodBody.Method, il);

                il.Append(targetNotNull);                    // Mark where the previous branch instruction should jump to                        

                base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, emitProceedTarget, proceedTargetMethod, proceedOpCode);
            }
开发者ID:kswoll,项目名称:sexy-proxy,代码行数:13,代码来源:InterfaceClassWeaver.cs

示例10: ParseInstruction

        public static Instruction ParseInstruction(ILProcessor processor, TypeDefinition type, XElement instrXML)
        {
            string fieldName = instrXML.Attribute("Field").Value;
            FieldDefinition field = type.Fields.FirstOrDefault(f => f.Name == fieldName);

            if (field == null)
            {
                Console.WriteLine("Couldn't find field named " + fieldName);
                return null;
            }

            return processor.Create(OpCodes.Ldfld, field);
        }
开发者ID:WMDesign,项目名称:PhiScript,代码行数:13,代码来源:Ldfld.cs

示例11: Initialize

        /// <summary>
        /// Emits the instructions that call <see cref="IInitialize.Initialize"/> on a given service instance.
        /// </summary>
        /// <param name="il"></param>
        /// <param name="module">The host module.</param>
        /// <param name="serviceInstance">The local variable that points to the current service instance.</param>
        public void Initialize(ILProcessor il, ModuleDefinition module, VariableDefinition serviceInstance)
        {
            var body = il.Body;
            var method = body.Method;
            var declaringType = method.DeclaringType;

            var targetField = GetTargetField(declaringType);
            if (targetField == null)
                return;

            var initializeType = module.ImportType<IInitialize>();

            il.Emit(OpCodes.Ldloc, serviceInstance);
            il.Emit(OpCodes.Isinst, initializeType);

            var initializeMethod = module.ImportMethod<IInitialize>("Initialize");
            var skipInitializationCall = il.Create(OpCodes.Nop);
            il.Emit(OpCodes.Brfalse, skipInitializationCall);

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, targetField);
            GetServiceHash(il, module, serviceInstance);

            var containsMethod = module.ImportMethod<Dictionary<int, int>>("ContainsKey");
            il.Emit(OpCodes.Callvirt, containsMethod);
            il.Emit(OpCodes.Brtrue, skipInitializationCall);

            // if (!__initializedServices.ContainsKey(currentService.GetHashCode()) {
            il.Emit(OpCodes.Ldloc, serviceInstance);
            il.Emit(OpCodes.Isinst, initializeType);
            il.Emit(OpCodes.Ldarg_0);

            il.Emit(OpCodes.Callvirt, initializeMethod);

            // __initializedServices.Add(hashCode, 0);
            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ldfld, targetField);
            GetServiceHash(il, module, serviceInstance);
            il.Emit(OpCodes.Ldc_I4_1);

            var addMethod = module.ImportMethod<Dictionary<int, int>>("Add");
            il.Emit(OpCodes.Callvirt, addMethod);

            il.Append(skipInitializationCall);
        }
开发者ID:philiplaureano,项目名称:Hiro,代码行数:51,代码来源:ServiceInitializer.cs

示例12: ParseInstruction

        public static Instruction ParseInstruction(ILProcessor processor, TypeDefinition type, XElement instrXML)
        {
            string assemblyName = instrXML.Attribute("Assembly").Value;
            string typeName = instrXML.Attribute("Type").Value;
            string methodName = instrXML.Attribute("Method").Value;

            // Get Assembly
            AssemblyDefinition assembly = Program.GetAssembly(assemblyName);

            if (assembly == null)
                return null;

            // Get Type
            TypeDefinition typeDefinition = assembly.MainModule.GetType(typeName);

            // Get Method
            MethodDefinition methodDefinition = typeDefinition.Methods.Single(m => m.Name == methodName);
            MethodReference methodReference =
                Program.GetAssembly("Assembly-CSharp").MainModule.Import(methodDefinition);

            // Generic Parameter Check
            if (instrXML.HasElements)
            {
                List<TypeReference> genericParameters = new List<TypeReference>();

                foreach (XElement genericParameter in instrXML.Elements("GenericParameter"))
                {
                    var gPAssemblyName = genericParameter.Attribute("Assembly").Value;
                    var gPType = genericParameter.Attribute("Type").Value;

                    AssemblyDefinition gPAssembly = Program.GetAssembly(gPAssemblyName);
                    TypeDefinition gPTypeDefinition = gPAssembly.MainModule.GetType(gPType);
                    TypeReference gPTypeReference =
                        Program.GetAssembly("Assembly-CSharp").MainModule.Import(gPTypeDefinition);

                    genericParameters.Add(gPTypeReference);
                }

                methodReference = methodReference.MakeGeneric(genericParameters.ToArray());
            }

            // Return Instruction
            return processor.Create(OpCodes.Call, methodReference);
        }
开发者ID:Longwelwind,项目名称:PhiScript,代码行数:44,代码来源:Call.cs

示例13: ImplementProceed

            protected override void ImplementProceed(MethodDefinition methodInfo, MethodBody methodBody, ILProcessor il, FieldReference methodInfoField, MethodReference proceed, Action<ILProcessor> emitProceedTarget, MethodReference proceedTargetMethod, OpCode proceedOpCode)
            {
                if (methodInfo.IsAbstract)
                {
                    CecilExtensions.CreateDefaultMethodImplementation(methodInfo, il);
                }
                else
                {
                    var targetNotNull = il.Create(OpCodes.Nop);
                    EmitProxyFromProceed(il);
                    il.Emit(OpCodes.Ldfld, target);              // Load "target" from "this"
                    il.Emit(OpCodes.Brtrue, targetNotNull);      // If target is not null, jump below

                    base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, _ => EmitProxyFromProceed(il), callBaseMethod, OpCodes.Call);

                    il.Append(targetNotNull);                    // Mark where the previous branch instruction should jump to                        
                
                    base.ImplementProceed(methodInfo, methodBody, il, methodInfoField, proceed, emitProceedTarget, proceedTargetMethod, proceedOpCode);
                }
            }
开发者ID:kswoll,项目名称:sexy-proxy,代码行数:20,代码来源:NonInterfaceClassWeaver.cs

示例14: ToNop

        public static int ToNop(ILProcessor ilp, Instruction ins, bool sameSize)
        {
            if (ins == null) return 0;

            int size = ins.GetSize();
            ins.OpCode = OpCodes.Nop;
            ins.Operand = null;
            if (sameSize)
            {
                for (int i = 1; i < size; i++)
                {
                    Instruction newIns = ilp.Create(OpCodes.Nop);
                    ilp.InsertAfter(ins, newIns);
                }
            }
            else
            {
                size = 1;
            }
            return size;
        }
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:21,代码来源:InsUtils.cs

示例15: GetMethod

        public static void GetMethod(Instruction i, ILProcessor proc, ModuleDefinition baseModule)
        {
            if (i.Operand is FieldReference
                && ((FieldReference)i.Operand).FullName.Contains("Monocle.Sprite`1<System.Int32> TowerFall.AwardInfo/<>c__DisplayClass")
                && ((FieldReference)i.Operand).FullName.Contains("::sprite"))
            {
                Stored = Instruction.Create(OpCodes.Ldfld, i.Operand as FieldReference);
            }

            if (i.OpCode == OpCodes.Callvirt && i.Next.OpCode != OpCodes.Br_S
                && ((MethodReference)i.Operand).FullName == "System.Void Monocle.Sprite`1<System.Int32>::Add(T,System.Int32)")
            {
                TypeDefinition graphicsComponent = baseModule.GetType("Monocle.GraphicsComponent");
                 var fieldReference = graphicsComponent.Fields.Single(f => f.Name == "Zoom");
                var instr = Instruction.Create(OpCodes.Stfld, fieldReference);
                var ldinstr = Instruction.Create(i.Next.OpCode);
                proc.InsertAfter(i, instr);
                proc.InsertAfter(i, proc.Create(OpCodes.Ldc_R4, (float)0.7));
                proc.InsertAfter(i, Stored);
                proc.InsertAfter(i, ldinstr);
            }
        }
开发者ID:Jonesey13,项目名称:TF-8-Player,代码行数:22,代码来源:AwardInfo.cs


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