OpCodes::TakesSingleByteArgument Method (OpCode)

 

Returns true or false if the supplied opcode takes a single byte argument.

Namespace:   System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public:
static bool TakesSingleByteArgument(
	OpCode inst
)

Parameters

inst
Type: System.Reflection.Emit::OpCode

An instance of an Opcode object.

Return Value

Type: System::Boolean

True or false.

This method can be used to find which MSIL opcodes are "short form", for use in optimized code.

TakesSingleByteArgument returns true if the OpCode instance takes a single byte argument in the following cases:

  • The opcode performs a branch instruction to a byte-sized address (for example, Br_S and Bgt_S).

  • The opcode pushes a byte value onto the stack (for example, Ldc_I4_S).

  • The opcode references a variable or argument via the byte-sized "short form" (for example, Ldloc_S and Stloc_S).

Otherwise, it returns false.

The example below demonstrates the use of TakesSingleByteArgument by reflecting on to the OpCodes class and testing to see whether each OpCode field takes a single-byte argument.

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) ) );
   }
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Windows Phone
Available since 8.1
Return to top
Show: