System.Reflection.FieldInfo.GetFieldFromHandle C# (CSharp) Method

GetFieldFromHandle() public static method

public static GetFieldFromHandle ( RuntimeFieldHandle handle ) : FieldInfo
handle RuntimeFieldHandle
return FieldInfo
        public static FieldInfo GetFieldFromHandle(RuntimeFieldHandle handle)
        {
            if (handle.IsNullHandle())
                throw new ArgumentException(Environment.GetResourceString("Argument_InvalidHandle"));
                
            FieldInfo f = RuntimeType.GetFieldInfo(handle);
                       
            if (f.DeclaringType != null && f.DeclaringType.IsGenericType)
                throw new ArgumentException(String.Format(
                    CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_FieldDeclaringTypeGeneric"), 
                    f.Name, f.DeclaringType.GetGenericTypeDefinition()));

            return f;            
        }           
        

Same methods

FieldInfo::GetFieldFromHandle ( RuntimeFieldHandle handle, RuntimeTypeHandle declaringType ) : FieldInfo

Usage Example

Esempio n. 1
0
        /// <summary>Returns the field identified by the specified metadata token, in the context defined by the specified generic type parameters.</summary>
        /// <returns>A <see cref="T:System.Reflection.FieldInfo" /> object representing the field that is identified by the specified metadata token.</returns>
        /// <param name="metadataToken">A metadata token that identifies a field in the module.</param>
        /// <param name="genericTypeArguments">An array of <see cref="T:System.Type" /> objects representing the generic type arguments of the type where the token is in scope, or null if that type is not generic. </param>
        /// <param name="genericMethodArguments">An array of <see cref="T:System.Type" /> objects representing the generic type arguments of the method where the token is in scope, or null if that method is not generic.</param>
        /// <exception cref="T:System.ArgumentException">
        ///   <paramref name="metadataToken" /> is not a token for a field in the scope of the current module.-or-<paramref name="metadataToken" /> identifies a field whose parent TypeSpec has a signature containing element type var (a type parameter of a generic type) or mvar (a type parameter of a generic method), and the necessary generic type arguments were not supplied for either or both of <paramref name="genericTypeArguments" /> and <paramref name="genericMethodArguments" />.</exception>
        /// <exception cref="T:System.ArgumentOutOfRangeException">
        ///   <paramref name="metadataToken" /> is not a valid token in the scope of the current module.</exception>
        public FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            ResolveTokenError error;
            IntPtr            intPtr = Module.ResolveFieldToken(this._impl, metadataToken, this.ptrs_from_types(genericTypeArguments), this.ptrs_from_types(genericMethodArguments), out error);

            if (intPtr == IntPtr.Zero)
            {
                throw this.resolve_token_exception(metadataToken, error, "Field");
            }
            return(FieldInfo.GetFieldFromHandle(new RuntimeFieldHandle(intPtr)));
        }
All Usage Examples Of System.Reflection.FieldInfo::GetFieldFromHandle