ערוך

שתף באמצעות


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(cli::array <System::Byte> ^ signature);
public int GetTokenFor (byte[] signature);
member this.GetTokenFor : byte[] -> int
Public Function GetTokenFor (signature As Byte()) As Integer

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

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);
public int GetTokenFor (System.Reflection.Emit.DynamicMethod method);
member this.GetTokenFor : System.Reflection.Emit.DynamicMethod -> int
Public Function GetTokenFor (method As DynamicMethod) As Integer

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

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);
public int GetTokenFor (RuntimeFieldHandle field);
member this.GetTokenFor : RuntimeFieldHandle -> int
Public Function GetTokenFor (field As RuntimeFieldHandle) As Integer

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

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);
public int GetTokenFor (RuntimeMethodHandle method);
member this.GetTokenFor : RuntimeMethodHandle -> int
Public Function GetTokenFor (method As RuntimeMethodHandle) As Integer

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

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);
public int GetTokenFor (RuntimeTypeHandle type);
member this.GetTokenFor : RuntimeTypeHandle -> int
Public Function GetTokenFor (type As RuntimeTypeHandle) As Integer

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

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(System::String ^ literal);
public int GetTokenFor (string literal);
member this.GetTokenFor : string -> int
Public Function GetTokenFor (literal As String) As Integer

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

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);
public int GetTokenFor (RuntimeFieldHandle field, RuntimeTypeHandle contextType);
member this.GetTokenFor : RuntimeFieldHandle * RuntimeTypeHandle -> int
Public Function GetTokenFor (field As RuntimeFieldHandle, contextType As RuntimeTypeHandle) As Integer

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

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);
public int GetTokenFor (RuntimeMethodHandle method, RuntimeTypeHandle contextType);
member this.GetTokenFor : RuntimeMethodHandle * RuntimeTypeHandle -> int
Public Function GetTokenFor (method As RuntimeMethodHandle, contextType As RuntimeTypeHandle) As Integer

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