本文整理汇总了C#中Mono.GetILProcessor方法的典型用法代码示例。如果您正苦于以下问题:C# Mono.GetILProcessor方法的具体用法?C# Mono.GetILProcessor怎么用?C# Mono.GetILProcessor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono
的用法示例。
在下文中一共展示了Mono.GetILProcessor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NopRet
private static void NopRet(Mono.Cecil.Cil.MethodBody methodBody)
{
if (methodBody == null)
{
return;
}
var ilProcessor = methodBody.GetILProcessor();
if (ilProcessor == null)
{
return;
}
foreach (var instruction in methodBody.Instructions.ToArray())
{
ilProcessor.Remove(instruction);
}
ilProcessor.Append(ilProcessor.Create(OpCodes.Nop));
ilProcessor.Append(ilProcessor.Create(OpCodes.Ret));
}
示例2: CopyBlock
public static void CopyBlock(Mono.Cecil.Cil.MethodBody body, int fromIndex, int startIndex, int endIndex)
{
//copy instructions startIndex to endIndex after fromIndex
if (fromIndex >= startIndex - 1 && fromIndex <= endIndex) return;
Collection<Instruction> instructions = body.Instructions;
Type icType = typeof(Collection<Instruction>);
Instruction[] alIns = (Instruction[])icType.InvokeMember("items",
BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance,
null, instructions, null);
int copyCount = endIndex - startIndex + 1;
Instruction[] al = new Instruction[instructions.Count + copyCount];
int curIndex = 0;
//0 to fromIndex
int count = fromIndex + 1;
Array.Copy(alIns, 0, al, curIndex, count);
curIndex += count;
//startIndex to endIndex
count = copyCount;
ILProcessor ilp = body.GetILProcessor();
for (int i = 0, j = curIndex; i < count; i++, j++)
{
Instruction ins = instructions[i + startIndex];
al[j] = InsUtils.CreateInstruction(ins.OpCode, ins.Operand);
}
curIndex += count;
//fromIndex+1 to end
count = instructions.Count - fromIndex - 1;
Array.Copy(alIns, fromIndex + 1, al, curIndex, count);
curIndex += count;
if (instructions.Count + copyCount != curIndex)
{
throw new ApplicationException("Internal CopyBlock error!");
}
al[fromIndex].Next = al[fromIndex + 1];
int index;
for (int i = 0; i < copyCount; i++)
{
index = i + fromIndex + 1;
al[index].Previous = al[index - 1];
al[index].Next = (index < al.Length - 1 ? al[index + 1] : null);
}
index = fromIndex + copyCount + 1;
if (index < al.Length)
{
al[index].Previous = al[index - 1];
}
alIns = null;
while (instructions.Count < al.Length)
{
instructions.Add(InsUtils.CreateInstruction(OpCodes.Nop, null));
}
alIns = (Instruction[])icType.InvokeMember("items",
BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance,
null, instructions, null);
Array.Copy(al, alIns, al.Length);
instructions[instructions.Count - 1].Next = null;
icType.InvokeMember("size",
BindingFlags.SetField | BindingFlags.NonPublic | BindingFlags.Instance,
null, instructions, new object[] { al.Length });
InsUtils.ComputeOffsets(instructions);
}