本文整理汇总了C#中IMethodBody.GetILAsByteArray方法的典型用法代码示例。如果您正苦于以下问题:C# IMethodBody.GetILAsByteArray方法的具体用法?C# IMethodBody.GetILAsByteArray怎么用?C# IMethodBody.GetILAsByteArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethodBody
的用法示例。
在下文中一共展示了IMethodBody.GetILAsByteArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpCodes
/// <summary>
/// </summary>
/// <param name="methodBody">
/// </param>
/// <param name="module">
/// </param>
/// <param name="genericContext">
/// </param>
/// <param name="stackCall">
/// </param>
/// <returns>
/// </returns>
public IEnumerable<OpCodePart> OpCodes(IMethodBody methodBody, IModule module, IGenericContext genericContext, Queue<IMethod> stackCall)
{
if (!methodBody.HasBody)
{
yield break;
}
var extended = false;
var startAddress = 0;
var currentAddress = 0;
var ilAsByteArray = methodBody.GetILAsByteArray();
var enumerator = ilAsByteArray.GetEnumerator();
while (enumerator.MoveNext())
{
var @byte = (byte)enumerator.Current;
if (@byte == 0xFE)
{
extended = true;
continue;
}
var code = (Code)(extended ? (@byte + 0xE1) : @byte);
extended = false;
var opCode = opCodesMap[code];
startAddress = currentAddress;
currentAddress += opCode.Size;
switch (code)
{
case Code.Br_S:
case Code.Beq_S:
case Code.Brtrue_S:
case Code.Brfalse_S:
case Code.Blt_S:
case Code.Blt_Un_S:
case Code.Bgt_S:
case Code.Bgt_Un_S:
case Code.Bge_S:
case Code.Bge_Un_S:
case Code.Ble_S:
case Code.Ble_Un_S:
case Code.Bne_Un_S:
case Code.Ldc_I4_S:
case Code.Ldloc_S:
case Code.Ldloca_S:
case Code.Stloc_S:
case Code.Leave_S:
case Code.Ldarg_S:
case Code.Starg_S:
case Code.Ldarga_S:
// read token, next
var token = ReadInt32ShortForm(enumerator, ref currentAddress);
var @int32 = token;
yield return new OpCodeInt32Part(opCode, startAddress, currentAddress, @int32);
continue;
case Code.Br:
case Code.Beq:
case Code.Brtrue:
case Code.Brfalse:
case Code.Blt:
case Code.Blt_Un:
case Code.Bgt:
case Code.Bgt_Un:
case Code.Bge:
case Code.Bge_Un:
case Code.Ble:
case Code.Ble_Un:
case Code.Bne_Un:
case Code.Ldc_I4:
case Code.Ldloc:
case Code.Stloc:
case Code.Leave:
case Code.Starg:
// read token, next
token = ReadInt32(enumerator, ref currentAddress);
@int32 = token;
yield return new OpCodeInt32Part(opCode, startAddress, currentAddress, @int32);
continue;
case Code.Ldc_I8:
// read token, next
var bytes = ReadBytes(enumerator, 8, ref currentAddress);
var @int64 = BitConverter.ToInt64(bytes, 0);
yield return new OpCodeInt64Part(opCode, startAddress, currentAddress, @int64);
//.........这里部分代码省略.........