OpCodes.TakesSingleByteArgument(OpCode) Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns true or false if the supplied opcode takes a single byte argument.
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
An instance of an Opcode object.
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) ) );
}
}
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
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: