Gets a System.Reflection.FieldInfo for the field represented by the specified handle, for the specified generic type.
- handle
- A RuntimeFieldHandle structure that contains the handle to the internal metadata representation of a field.
- declaringType
- A RuntimeTypeHandle structure that contains the handle to the generic type that defines the field.
A System.Reflection.FieldInfo object representing the field specified by handle, in the generic type specified by declaringType.
Handles are valid only in the application domain in which they were obtained.
The recommended practice is that declaringType should always be the runtime type handle of the constructed type that handle belongs to. That is, if handle is a runtime field handle for a field that belongs to MyType<int> (MyType(Of Integer) in Visual Basic), declaringType is the runtime type handle for MyType<int>. Do not use the runtime type handle of the generic type definition, unless the runtime field handle represents a field on the generic type definition.
Implementations are compatible in some cases. For example, a single implementation is shared by all types that are constructed from a particular generic type definition by using reference types for the generic type arguments. For example, MyType<string>, MyType<object>, and MyType<ArrayList> all share the same implementation. In this situation, the System.Reflection.FieldInfo object that is returned represents a field on the type that declaringType specifies, regardless of the original source of handle. This practice is not recommended, because it works only if the generic type arguments of the constructed type are reference types.
If a generic argument is a value type, the runtime type handle of the constructed type is not compatible with runtime field handles from constructions that have a reference type in the same generic parameter position, or that have a different value type in that position. In that case, the only way to use the FieldInfo.GetFieldFromHandle(RuntimeFieldHandle, RuntimeTypeHandle) overload is to ensure that declaringType is the runtime type handle for the constructed type that handle belongs to.