本文整理汇总了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;
}
}