當前位置: 首頁>>代碼示例>>C#>>正文


C# ILProcessor.Replace方法代碼示例

本文整理匯總了C#中Mono.Cecil.Cil.ILProcessor.Replace方法的典型用法代碼示例。如果您正苦於以下問題:C# ILProcessor.Replace方法的具體用法?C# ILProcessor.Replace怎麽用?C# ILProcessor.Replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.Cil.ILProcessor的用法示例。


在下文中一共展示了ILProcessor.Replace方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

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

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

示例3: ReplaceFixedArrayStatement

        private void ReplaceFixedArrayStatement(MethodDefinition method, ILProcessor ilProcessor, Instruction fixedtoPatch)
        {
            var paramT = ((GenericInstanceMethod)fixedtoPatch.Operand).GenericArguments[0];
            // Preparing locals
            // local(0) T*
            method.Body.Variables.Add(new VariableDefinition("pin", new PinnedType(new ByReferenceType(paramT))));

            int index = method.Body.Variables.Count - 1;

            Instruction ldlocFixed;
            Instruction stlocFixed;
            switch (index)
            {
                case 0:
                    stlocFixed = ilProcessor.Create(OpCodes.Stloc_0);
                    ldlocFixed = ilProcessor.Create(OpCodes.Ldloc_0);
                    break;
                case 1:
                    stlocFixed = ilProcessor.Create(OpCodes.Stloc_1);
                    ldlocFixed = ilProcessor.Create(OpCodes.Ldloc_1);
                    break;
                case 2:
                    stlocFixed = ilProcessor.Create(OpCodes.Stloc_2);
                    ldlocFixed = ilProcessor.Create(OpCodes.Ldloc_2);
                    break;
                case 3:
                    stlocFixed = ilProcessor.Create(OpCodes.Stloc_3);
                    ldlocFixed = ilProcessor.Create(OpCodes.Ldloc_3);
                    break;
                default:
                    stlocFixed = ilProcessor.Create(OpCodes.Stloc, index);
                    ldlocFixed = ilProcessor.Create(OpCodes.Ldloc, index);
                    break;
            }

            var instructionLdci40 = ilProcessor.Create(OpCodes.Ldc_I4_0);
            ilProcessor.InsertBefore(fixedtoPatch, instructionLdci40);
            var instructionLdElema = ilProcessor.Create(OpCodes.Ldelema, paramT);
            ilProcessor.InsertBefore(fixedtoPatch, instructionLdElema);
            ilProcessor.InsertBefore(fixedtoPatch, stlocFixed);
            ilProcessor.Replace(fixedtoPatch, ldlocFixed);
        }
開發者ID:RecursiveCall,項目名稱:SharpDX,代碼行數:42,代碼來源:InteropApp.cs

示例4: ReplaceSizeOfStructGeneric

 private void ReplaceSizeOfStructGeneric(MethodDefinition method, ILProcessor ilProcessor, Instruction fixedtoPatch)
 {
     var paramT = ((GenericInstanceMethod)fixedtoPatch.Operand).GenericArguments[0];
     var copyInstruction = ilProcessor.Create(OpCodes.Sizeof, paramT);
     ilProcessor.Replace(fixedtoPatch, copyInstruction);
 }
開發者ID:RecursiveCall,項目名稱:SharpDX,代碼行數:6,代碼來源:InteropApp.cs

示例5: ReplaceIncrementPinnedStructGeneric

        private void ReplaceIncrementPinnedStructGeneric(MethodDefinition method, ILProcessor ilProcessor, Instruction incrementPinnedToPatch)
        {
            var paramT = ((GenericInstanceMethod)incrementPinnedToPatch.Operand).GenericArguments[0];

            var sizeOfInst = ilProcessor.Create(OpCodes.Sizeof, paramT);

            ilProcessor.Replace(incrementPinnedToPatch, sizeOfInst);
            ilProcessor.InsertAfter(sizeOfInst, ilProcessor.Create(OpCodes.Add));
        }
開發者ID:Powerino73,項目名稱:paradox,代碼行數:9,代碼來源:InteropProcessor.cs

示例6: ReplaceWriteInline

 private static void ReplaceWriteInline(MethodReference methodDescr, ILProcessor ilGen, Instruction instructionToPatch)
 {
     TypeReference paramT = ((GenericInstanceMethod) instructionToPatch.Operand).GenericArguments[0];
     Instruction newInstruction = ilGen.Create(OpCodes.Cpobj, paramT);
     ilGen.Replace(instructionToPatch, newInstruction);
 }
開發者ID:Relfos,項目名稱:assimp_terra_exporter,代碼行數:6,代碼來源:Program.cs

示例7: ReplaceBranchesWithLeaves

 private void ReplaceBranchesWithLeaves(ILProcessor il, ExceptionHandler handler)
 {
     var current = handler.TryStart;
     while (current != handler.TryEnd)
     {
         var next = current.Next;
         if (current.OpCode == OpCodes.Br && ((Instruction)current.Operand).Offset > handler.TryEnd.Offset)
             il.Replace(current, il.Create(OpCodes.Leave, (Instruction)current.Operand));
         current = next;
     }
 }
開發者ID:ropean,項目名稱:Usable,代碼行數:11,代碼來源:ModuleWeaver.cs


注:本文中的Mono.Cecil.Cil.ILProcessor.Replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。