Bagikan melalui


OpCodes.TakesSingleByteArgument(OpCode) Metode

Definisi

Mengembalikan true atau false jika opcode yang disediakan mengambil argumen byte tunggal.

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

Parameter

inst
OpCode

Instans objek Opcode.

Mengembalikan

true atau false.

Keterangan

Metode ini dapat digunakan untuk menemukan opcode MSIL mana yang "bentuk pendek", untuk digunakan dalam kode yang dioptimalkan.

TakesSingleByteArgumentmengembalikan jika OpCode instans true mengambil argumen byte tunggal dalam kasus berikut:

  • Opcode melakukan instruksi cabang ke alamat berukuran byte (misalnya, Br_S dan Bgt_S).

  • Opcode mendorong nilai byte ke tumpukan (misalnya, Ldc_I4_S).

  • Opcode mereferensikan variabel atau argumen melalui "bentuk pendek" berukuran byte (misalnya, Ldloc_S dan Stloc_S).

Jika tidak, ia kembali false.

Contoh di bawah ini menunjukkan penggunaan TakesSingleByteArgument dengan merefleksikan ke OpCodes kelas dan pengujian untuk melihat apakah setiap OpCode bidang mengambil argumen byte tunggal.

int main()
{
   
   // We need a blank OpCode Object for reference when calling FieldInfo::GetValue().
   OpCode blankOpCode;
   Type^ myOpCodesType = Type::GetType( "System.Reflection.Emit.OpCodes" );
   array<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.
   System::Collections::IEnumerator^ myEnum = listOfOpCodes->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      FieldInfo^ opCodeFI = safe_cast<FieldInfo^>(myEnum->Current);
      Object^ theOpCode = opCodeFI->GetValue( blankOpCode );
      Console::WriteLine( " {0}: {1}", opCodeFI->Name, OpCodes::TakesSingleByteArgument(  *dynamic_cast<OpCode^>(theOpCode) ) );
   }
}

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

Berlaku untuk