FieldInfo Class
TOC
Collapse the table of content
Expand the table of content

FieldInfo Class

 

Discovers the attributes of a field and provides access to field metadata.

Namespace:   System.Reflection
Assembly:  mscorlib (in mscorlib.dll)


[SerializableAttribute]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ComVisibleAttribute(true)]
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public abstract class FieldInfo : MemberInfo, _FieldInfo

NameDescription
System_CAPS_protmethodFieldInfo()

Initializes a new instance of the FieldInfo class.

NameDescription
System_CAPS_pubpropertyAttributes

Gets the attributes associated with this field.

System_CAPS_pubpropertyCustomAttributes

Gets a collection that contains this member's custom attributes.(Inherited from MemberInfo.)

System_CAPS_pubpropertyDeclaringType

Gets the class that declares this member.(Inherited from MemberInfo.)

System_CAPS_pubpropertyFieldHandle

Gets a RuntimeFieldHandle, which is a handle to the internal metadata representation of a field.

System_CAPS_pubpropertyFieldType

Gets the type of this field object.

System_CAPS_pubpropertyIsAssembly

Gets a value indicating whether the potential visibility of this field is described by FieldAttributes.Assembly; that is, the field is visible at most to other types in the same assembly, and is not visible to derived types outside the assembly.

System_CAPS_pubpropertyIsFamily

Gets a value indicating whether the visibility of this field is described by FieldAttributes.Family; that is, the field is visible only within its class and derived classes.

System_CAPS_pubpropertyIsFamilyAndAssembly

Gets a value indicating whether the visibility of this field is described by FieldAttributes.FamANDAssem; that is, the field can be accessed from derived classes, but only if they are in the same assembly.

System_CAPS_pubpropertyIsFamilyOrAssembly

Gets a value indicating whether the potential visibility of this field is described by FieldAttributes.FamORAssem; that is, the field can be accessed by derived classes wherever they are, and by classes in the same assembly.

System_CAPS_pubpropertyIsInitOnly

Gets a value indicating whether the field can only be set in the body of the constructor.

System_CAPS_pubpropertyIsLiteral

Gets a value indicating whether the value is written at compile time and cannot be changed.

System_CAPS_pubpropertyIsNotSerialized

Gets a value indicating whether this field has the NotSerialized attribute.

System_CAPS_pubpropertyIsPinvokeImpl

Gets a value indicating whether the corresponding PinvokeImpl attribute is set in FieldAttributes.

System_CAPS_pubpropertyIsPrivate

Gets a value indicating whether the field is private.

System_CAPS_pubpropertyIsPublic

Gets a value indicating whether the field is public.

System_CAPS_pubpropertyIsSecurityCritical

Gets a value that indicates whether the current field is security-critical or security-safe-critical at the current trust level.

System_CAPS_pubpropertyIsSecuritySafeCritical

Gets a value that indicates whether the current field is security-safe-critical at the current trust level.

System_CAPS_pubpropertyIsSecurityTransparent

Gets a value that indicates whether the current field is transparent at the current trust level.

System_CAPS_pubpropertyIsSpecialName

Gets a value indicating whether the corresponding SpecialName attribute is set in the FieldAttributes enumerator.

System_CAPS_pubpropertyIsStatic

Gets a value indicating whether the field is static.

System_CAPS_pubpropertyMemberType

Gets a MemberTypes value indicating that this member is a field.(Overrides MemberInfo.MemberType.)

System_CAPS_pubpropertyMetadataToken

Gets a value that identifies a metadata element.(Inherited from MemberInfo.)

System_CAPS_pubpropertyModule

Gets the module in which the type that declares the member represented by the current MemberInfo is defined.(Inherited from MemberInfo.)

System_CAPS_pubpropertyName

Gets the name of the current member.(Inherited from MemberInfo.)

System_CAPS_pubpropertyReflectedType

Gets the class object that was used to obtain this instance of MemberInfo.(Inherited from MemberInfo.)

NameDescription
System_CAPS_pubmethodEquals(Object)

Returns a value that indicates whether this instance is equal to a specified object.(Overrides MemberInfo.Equals(Object).)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetCustomAttributes(Boolean)

When overridden in a derived class, returns an array of all custom attributes applied to this member. (Inherited from MemberInfo.)

System_CAPS_pubmethodGetCustomAttributes(Type, Boolean)

When overridden in a derived class, returns an array of custom attributes applied to this member and identified by Type.(Inherited from MemberInfo.)

System_CAPS_pubmethodGetCustomAttributesData()

Returns a list of CustomAttributeData objects representing data about the attributes that have been applied to the target member.(Inherited from MemberInfo.)

System_CAPS_pubmethodSystem_CAPS_staticGetFieldFromHandle(RuntimeFieldHandle)

Gets a FieldInfo for the field represented by the specified handle.

System_CAPS_pubmethodSystem_CAPS_staticGetFieldFromHandle(RuntimeFieldHandle, RuntimeTypeHandle)

Gets a FieldInfo for the field represented by the specified handle, for the specified generic type.

System_CAPS_pubmethodGetHashCode()

Returns the hash code for this instance.(Overrides MemberInfo.GetHashCode().)

System_CAPS_pubmethodGetOptionalCustomModifiers()

Gets an array of types that identify the optional custom modifiers of the field.

System_CAPS_pubmethodGetRawConstantValue()

Returns a literal value associated with the field by a compiler.

System_CAPS_pubmethodGetRequiredCustomModifiers()

Gets an array of types that identify the required custom modifiers of the property.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetValue(Object)

When overridden in a derived class, returns the value of a field supported by a given object.

System_CAPS_pubmethodGetValueDirect(TypedReference)

Returns the value of a field supported by a given object.

System_CAPS_pubmethodIsDefined(Type, Boolean)

When overridden in a derived class, indicates whether one or more attributes of the specified type or of its derived types is applied to this member.(Inherited from MemberInfo.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodSetValue(Object, Object)

Sets the value of the field supported by the given object.

System_CAPS_pubmethodSetValue(Object, Object, BindingFlags, Binder, CultureInfo)

When overridden in a derived class, sets the value of the field supported by the given object.

System_CAPS_pubmethodSetValueDirect(TypedReference, Object)

Sets the value of the field supported by the given object.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_puboperatorSystem_CAPS_staticEquality(FieldInfo, FieldInfo)

Indicates whether two FieldInfo objects are equal.

System_CAPS_puboperatorSystem_CAPS_staticInequality(FieldInfo, FieldInfo)

Indicates whether two FieldInfo objects are not equal.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethod_FieldInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_FieldInfo.GetType()

Gets a Type object representing the FieldInfo type.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_FieldInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can then be used to get the type information for an interface.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_FieldInfo.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

System_CAPS_pubinterfaceSystem_CAPS_privmethod_FieldInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetType()

Gets a Type object representing the MemberInfo class.(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can then be used to get the type information for an interface.(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from MemberInfo.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_MemberInfo.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.(Inherited from MemberInfo.)

NameDescription
System_CAPS_pubmethodGetCustomAttribute(Type)

Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttribute(Type, Boolean)

Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttribute<T>()

Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttribute<T>(Boolean)

Overloaded. Retrieves a custom attribute of a specified type that is applied to a specified member, and optionally inspects the ancestors of that member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttributes()

Overloaded. Retrieves a collection of custom attributes that are applied to a specified member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttributes(Type)

Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodGetCustomAttributes<T>(Boolean)

Overloaded. Retrieves a collection of custom attributes of a specified type that are applied to a specified member, and optionally inspects the ancestors of that member.(Defined by CustomAttributeExtensions.)

System_CAPS_pubmethodIsDefined(Type)

Overloaded. Indicates whether custom attributes of a specified type are applied to a specified member.(Defined by CustomAttributeExtensions.)

The field information is obtained from metadata. The FieldInfo class does not have a public constructor. FieldInfo objects are obtained by calling either the GetFields or GetField method of a Type object.

Fields are variables defined in the class. FieldInfo provides access to the metadata for a field within a class and provides dynamic set and get functionality for the field. The class is not loaded into memory until invoke or get is called on the object.

Notes to Inheritors:

When you inherit from FieldInfo, you must override the following members: GetValue and SetValue.

The following example uses the Type.GetFields method to get the field-related information from the FieldInfo class, and then displays field attributes.

using System;
using System.Reflection;

public class FieldInfoClass
{
    public int myField1 = 0;
    protected string myField2 = null;
    public static void Main()
    {
        FieldInfo[] myFieldInfo;
        Type myType = typeof(FieldInfoClass);
        // Get the type and fields of FieldInfoClass.
        myFieldInfo = myType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance
            | BindingFlags.Public);
        Console.WriteLine("\nThe fields of " + 
            "FieldInfoClass are \n");
        // Display the field information of FieldInfoClass.
        for(int i = 0; i < myFieldInfo.Length; i++)
        {
            Console.WriteLine("\nName            : {0}", myFieldInfo[i].Name);
            Console.WriteLine("Declaring Type  : {0}", myFieldInfo[i].DeclaringType);
            Console.WriteLine("IsPublic        : {0}", myFieldInfo[i].IsPublic);
            Console.WriteLine("MemberType      : {0}", myFieldInfo[i].MemberType);
            Console.WriteLine("FieldType       : {0}", myFieldInfo[i].FieldType);
            Console.WriteLine("IsFamily        : {0}", myFieldInfo[i].IsFamily);
        }
    }
}

SecurityAction.InheritanceDemand

for full trust for inheritors. This class cannot be inherited by partially trusted code.

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1

This type is thread safe.

Return to top
Show:
© 2016 Microsoft