OpCodes.TakesSingleByteArgument(OpCode) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
如果提供的 Opcode 採用單一位元組引數,則傳回 True 或 False。
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
參數
- inst
- OpCode
Opcode 物件的執行個體。
傳回
true
或 false
。
備註
這個方法可用來尋找哪些 MSIL opcode 為「簡短形式」,以用於優化程序代碼。
TakesSingleByteArgument
true
如果OpCode實體在下列情況下採用單一位元組自變數,則會傳回 :
opcode 會將位元組值推送至堆疊 (例如, Ldc_I4_S) 。
否則會傳回 false
。
下列範例示範 如何使用 TakesSingleByteArgument
,將 反映至 OpCodes
類別和測試,以查看每個 OpCode
欄位是否採用單一位元組自變數。
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