DynamicILInfo.GetTokenFor Method

Definition

Gets a token, valid in the scope of the current DynamicILInfo, representing a string, field, method, type, or signature in the MSIL stream for the associated dynamic method.

Overloads

GetTokenFor(Byte[])

Gets a token, valid in the scope of the current DynamicILInfo, representing the signature for the associated dynamic method.

GetTokenFor(DynamicMethod)

Gets a token, valid in the scope of the current DynamicILInfo, representing a dynamic method to be called from the associated method.

GetTokenFor(RuntimeFieldHandle)

Gets a token, valid in the scope of the current DynamicILInfo, representing a field to be accessed from the associated dynamic method.

GetTokenFor(RuntimeMethodHandle)

Gets a token, valid in the scope of the current DynamicILInfo, representing a method to be accessed from the associated dynamic method.

GetTokenFor(RuntimeTypeHandle)

Gets a token, valid in the scope of the current DynamicILInfo, representing a type to be used in the associated dynamic method.

GetTokenFor(String)

Gets a token, valid in the scope of the current DynamicILInfo, representing a string literal to be used in the associated dynamic method.

GetTokenFor(RuntimeFieldHandle, RuntimeTypeHandle)

Gets a token, valid in the scope of the current DynamicILInfo, representing a field to be accessed from the associated dynamic method; the field is on the specified generic type.

GetTokenFor(RuntimeMethodHandle, RuntimeTypeHandle)

Gets a token, valid in the scope of the current DynamicILInfo, representing a method on a generic type.

GetTokenFor(Byte[])

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing the signature for the associated dynamic method.

public int GetTokenFor (byte[] signature);

Parameters

signature
Byte[]

An array that contains the signature.

Returns

A token that can be embedded in the metadata and the MSIL stream for the associated dynamic method.

Remarks

For information on signature blobs, see the Common Language Infrastructure (CLI) documentation, especially "Partition II: Metadata Definition and Semantics". For more information, see ECMA 335 Common Language Infrastructure (CLI).

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(DynamicMethod)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a dynamic method to be called from the associated method.

public int GetTokenFor (System.Reflection.Emit.DynamicMethod method);

Parameters

method
DynamicMethod

The dynamic method to call.

Returns

A token that can be embedded in the MSIL stream for the associated dynamic method, as the target of an MSIL instruction.

Remarks

The token returned by this method overload allows you to call a dynamic method from the dynamic method associated with the current DynamicILInfo object. To call the associated dynamic method recursively, pass the value of the DynamicMethod property.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(RuntimeFieldHandle)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a field to be accessed from the associated dynamic method.

public int GetTokenFor (RuntimeFieldHandle field);

Parameters

field
RuntimeFieldHandle

The field to be accessed.

Returns

A token that can be used as the operand of an MSIL instruction that accesses fields, in the scope of the current DynamicILInfo object.

Remarks

You must obtain a token for any field that will be accessed by the dynamic method associated with the current DynamicILInfo object. Use the Type.GetField method to get a FieldInfo for the field you want to access, then use the FieldHandle property to get the RuntimeFieldHandle.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(RuntimeMethodHandle)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a method to be accessed from the associated dynamic method.

public int GetTokenFor (RuntimeMethodHandle method);

Parameters

method
RuntimeMethodHandle

The method to be accessed.

Returns

A token that can be used as the operand of an MSIL instruction that accesses methods, such as Call or Ldtoken, in the scope of the current DynamicILInfo object.

Remarks

You must obtain a token for any method that will be accessed by the dynamic method associated with the current DynamicILInfo object. Use the Type.GetMethod method to get a MethodInfo for the method you want to access, and then use the MethodHandle property to get the RuntimeMethodHandle.

Note

For a method that belongs to a generic type, use the GetTokenFor(RuntimeMethodHandle, RuntimeTypeHandle) method overload and specify a RuntimeTypeHandle for the generic type.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(RuntimeTypeHandle)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a type to be used in the associated dynamic method.

public int GetTokenFor (RuntimeTypeHandle type);

Parameters

type
RuntimeTypeHandle

The type to be used.

Returns

A token that can be used as the operand of an MSIL instruction that requires a type, in the scope of the current DynamicILInfo object.

Remarks

The token returned by this method overload allows you to define a local variable type, and emit MSIL to create an instance of a type in the dynamic method associated with the current DynamicILInfo object.

To get a RuntimeTypeHandle representing a type, use the Type.TypeHandle property.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(String)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a string literal to be used in the associated dynamic method.

public int GetTokenFor (string literal);

Parameters

literal
String

The string to be used.

Returns

A token that can be used as the operand of an MSIL instruction that requires a string, in the scope of the current DynamicILInfo object.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(RuntimeFieldHandle, RuntimeTypeHandle)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a field to be accessed from the associated dynamic method; the field is on the specified generic type.

public int GetTokenFor (RuntimeFieldHandle field, RuntimeTypeHandle contextType);

Parameters

field
RuntimeFieldHandle

The field to be accessed.

contextType
RuntimeTypeHandle

The generic type the field belongs to.

Returns

A token that can be used as the operand of an MSIL instruction that accesses fields in the scope of the current DynamicILInfo object.

Remarks

You must obtain a token for any field that will be accessed by the dynamic method associated with the current DynamicILInfo object. Use the Type.GetField method to get a FieldInfo for the field you want to access, and then use the FieldHandle property to get the RuntimeFieldHandle.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1

GetTokenFor(RuntimeMethodHandle, RuntimeTypeHandle)

Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs
Source:
DynamicILGenerator.cs

Gets a token, valid in the scope of the current DynamicILInfo, representing a method on a generic type.

public int GetTokenFor (RuntimeMethodHandle method, RuntimeTypeHandle contextType);

Parameters

method
RuntimeMethodHandle

The method.

contextType
RuntimeTypeHandle

The generic type the method belongs to.

Returns

A token that can be used as the operand of an MSIL instruction that accesses methods, such as Call or Ldtoken, in the scope of the current DynamicILInfo object.

Remarks

You must obtain a token for any method that will be called by the dynamic method associated with the current DynamicILInfo object. Use the Type.GetMethod method to get a MethodInfo for the method you want to call, and then use the MethodHandle property to get the RuntimeMethodHandle.

Applies to

.NET 9 and other versions
Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 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 2.1