OpCodes.TakesSingleByteArgument(OpCode) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
如果提供的操作码采用单字节自变量则返回真或假。
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
操作码对象的实例。
返回
true
或 false
。
注解
此方法可用于查找哪些 MSIL 操作码是“短格式”,以便在优化代码中使用。
TakesSingleByteArgument
true
如果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