OpCodes.TakesSingleByteArgument(OpCode) Metodo

Definizione

Restituisce true o false se il codice operativo fornito accetta un singolo argomento di byte.

public:
 static bool TakesSingleByteArgument(System::Reflection::Emit::OpCode inst);
public static bool TakesSingleByteArgument(System.Reflection.Emit.OpCode inst);
static member TakesSingleByteArgument : System.Reflection.Emit.OpCode -> bool
Public Shared Function TakesSingleByteArgument (inst As OpCode) As Boolean

Parametri

inst
OpCode

Istanza di un oggetto Opcode.

Valori restituiti

true o false.

Commenti

Questo metodo può essere usato per trovare i codici opcode MSIL "short form", da usare nel codice ottimizzato.

TakesSingleByteArgument restituisce true se l'istanza OpCode accetta un singolo argomento di byte nei casi seguenti:

  • Il codice operativo esegue un'istruzione di ramo in un indirizzo di dimensioni byte , ad esempio Br_S e Bgt_S.

  • Il codice operativo inserisce un valore di byte nello stack (ad esempio, Ldc_I4_S).

  • Il codice operativo fa riferimento a una variabile o a un argomento tramite la "forma breve" di dimensioni byte (ad esempio, Ldloc_S e Stloc_S).

In caso contrario, restituisce false.

L'esempio seguente illustra l'uso di TakesSingleByteArgument riflettendo sulla OpCodes classe e verificando se ogni OpCode campo accetta un argomento a byte singolo.


public static void Main()
{
   // We need a blank OpCode object for reference when calling FieldInfo.GetValue().

   OpCode blankOpCode = new OpCode();

   Type myOpCodesType = Type.GetType("System.Reflection.Emit.OpCodes");
   FieldInfo[] listOfOpCodes = myOpCodesType.GetFields();

   Console.WriteLine("Which OpCodes take single-byte arguments?");
   Console.WriteLine("-----------------------------------------");

   // Now, let's reflect on each FieldInfo and create an instance of the OpCode it represents.

   foreach (FieldInfo opCodeFI in listOfOpCodes)
   {
    object theOpCode = opCodeFI.GetValue(blankOpCode);
    
    Console.WriteLine("{0}: {1}", opCodeFI.Name,
              OpCodes.TakesSingleByteArgument((OpCode)theOpCode).ToString());
   }
}

Public Shared Sub Main()

   ' We need a blank OpCode object for reference when calling FieldInfo.GetValue().

   Dim blankOpCode As New OpCode()
   
   Dim myOpCodesType As Type = Type.GetType("System.Reflection.Emit.OpCodes")
   Dim listOfOpCodes As FieldInfo() = myOpCodesType.GetFields()
   
   Console.WriteLine("Which OpCodes take single-byte arguments?")
   Console.WriteLine("-----------------------------------------")
   
   ' Now, let's reflect on each FieldInfo and create an instance of the OpCode it represents.
   Dim opCodeFI As FieldInfo
   For Each opCodeFI In  listOfOpCodes
      Dim theOpCode As Object = opCodeFI.GetValue(blankOpCode)
      
      Console.WriteLine("{0}: {1}", opCodeFI.Name, _
            OpCodes.TakesSingleByteArgument(CType(theOpCode, OpCode)).ToString())
   Next opCodeFI

End Sub

Si applica a