本文整理匯總了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))));
}
示例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))));
}
示例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);
}
示例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);
}
示例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));
}
示例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);
}
示例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;
}
}