本文整理汇总了C#中System.Reflection.MethodBase.GetInstructions方法的典型用法代码示例。如果您正苦于以下问题:C# MethodBase.GetInstructions方法的具体用法?C# MethodBase.GetInstructions怎么用?C# MethodBase.GetInstructions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodBase
的用法示例。
在下文中一共展示了MethodBase.GetInstructions方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteMethodBody
public static void WriteMethodBody (TextWriter writer, MethodBase method)
{
foreach (var instruction in method.GetInstructions ()) {
writer.Write ('\t');
WriteInstruction (writer, instruction);
writer.WriteLine ();
}
}
示例2: Match
public static MatchContext Match(MethodBase method, ILPattern pattern) {
IList<Instruction> instructions = method.GetInstructions();
if (instructions.Count == 0)
throw new ArgumentException();
var context = new MatchContext(instructions[0]);
pattern.Match(context);
return context;
}
示例3: Match
public static MatchContext Match (MethodBase method, ILPattern pattern) {
if (method == null)
throw new ArgumentNullException("method");
if (pattern == null)
throw new ArgumentNullException("pattern");
var instructions = method.GetInstructions();
if (instructions.Count == 0)
throw new ArgumentException();
var context = new MatchContext(instructions[0]);
pattern.Match(context);
return context;
}
示例4: MapInstructions
private void MapInstructions(MethodBase method, MethodDefinition method_definition)
{
var instructions = method.GetInstructions();
foreach (var instruction in instructions)
{
var il = method_definition.Body.GetILProcessor();
var op = OpCodeFor(instruction);
switch (op.OperandType)
{
case OperandType.InlineNone:
il.Emit(op);
break;
case OperandType.InlineMethod:
il.Emit(op, CreateReference((MethodBase)instruction.Operand, method_definition));
break;
case OperandType.InlineField:
il.Emit(op, CreateReference((FieldInfo)instruction.Operand, method_definition));
break;
case OperandType.InlineType:
il.Emit(op, CreateReference((Type)instruction.Operand, method_definition));
break;
case OperandType.InlineTok:
var member = (MemberInfo)instruction.Operand;
if (member is Type)
il.Emit(op, CreateTokenReference((Type)instruction.Operand, method_definition));
else if (member is FieldInfo)
il.Emit(op, CreateReference((FieldInfo)instruction.Operand, method_definition));
else if (member is MethodBase)
il.Emit(op, CreateTokenReference((MethodBase)instruction.Operand, method_definition));
else
throw new NotSupportedException();
break;
case OperandType.ShortInlineI:
if (op.Code == Code.Ldc_I4_S)
il.Emit(op, (sbyte)instruction.Operand);
else
il.Emit(op, (byte)instruction.Operand);
break;
case OperandType.InlineI:
il.Emit(op, (int)instruction.Operand);
break;
case OperandType.InlineI8:
il.Emit(op, (long)instruction.Operand);
break;
case OperandType.ShortInlineR:
il.Emit(op, (float)instruction.Operand);
break;
case OperandType.InlineR:
il.Emit(op, (double)instruction.Operand);
break;
case OperandType.ShortInlineVar:
case OperandType.InlineVar:
il.Emit(op, VariableFor(instruction, method_definition));
break;
case OperandType.ShortInlineArg:
case OperandType.InlineArg:
il.Emit(op, ParameterFor(instruction, method_definition));
break;
case OperandType.InlineString:
il.Emit(op, (string)instruction.Operand);
break;
case OperandType.ShortInlineBrTarget:
case OperandType.InlineBrTarget:
il.Emit(op, MC.Cil.Instruction.Create(OpCodes.Nop));
break;
case OperandType.InlineSwitch:
il.Emit(op, new[] { MC.Cil.Instruction.Create(OpCodes.Nop) });
break;
case OperandType.InlineSig:
throw new NotSupportedException("InlineSig");
default:
throw new NotSupportedException(op.OperandType.ToString());
}
}
foreach (var instruction in instructions)
{
var op = OpCodeFor(instruction);
switch (op.OperandType)
{
case OperandType.ShortInlineBrTarget:
case OperandType.InlineBrTarget:
var br = OffsetToInstruction(instruction.Offset, instructions, method_definition);
var target = (MR.Instruction)instruction.Operand;
if (target != null)
br.Operand = OffsetToInstruction(target.Offset, instructions, method_definition);
break;
case OperandType.InlineSwitch:
var @switch = OffsetToInstruction(instruction.Offset, instructions, method_definition);
@switch.Operand = ((MR.Instruction[])instruction.Operand).Select(i => OffsetToInstruction(i.Offset, instructions, method_definition)).ToArray();
break;
}
}
}
示例5: MapExceptions
private void MapExceptions(MethodBase method, MethodDefinition method_definition)
{
var body = method.GetMethodBody();
if (body == null)
return;
var instructions = method.GetInstructions();
foreach (var clause in body.ExceptionHandlingClauses)
{
var handler = new ExceptionHandler((ExceptionHandlerType)clause.Flags)
{
TryStart = OffsetToInstruction(clause.TryOffset, instructions, method_definition),
TryEnd = OffsetToInstruction(clause.TryOffset + clause.TryLength, instructions, method_definition),
HandlerStart = OffsetToInstruction(clause.HandlerOffset, instructions, method_definition),
HandlerEnd = OffsetToInstruction(clause.HandlerOffset + clause.HandlerLength, instructions, method_definition)
};
switch (handler.HandlerType)
{
case ExceptionHandlerType.Catch:
handler.CatchType = CreateReference(clause.CatchType, method_definition);
break;
case ExceptionHandlerType.Filter:
handler.FilterStart = OffsetToInstruction(clause.FilterOffset, instructions, method_definition);
break;
}
method_definition.Body.ExceptionHandlers.Add(handler);
}
}