Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Reflection.​FieldInfo

Assembly: System.Runtime

Inheritance: object → MemberInfo → FieldInfo

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

Properties

Attributes
Gets the attributes associated with this field.
FieldHandle
Gets a <see langword="RuntimeFieldHandle" /> , which is a handle to the internal metadata representation of a field.
public Type
FieldType
Gets the type of this field object.
public bool
IsAssembly
Gets a value indicating whether the potential visibility of this field is described by <see cref="F:System.Reflection.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.
public bool
IsFamily
Gets a value indicating whether the visibility of this field is described by <see cref="F:System.Reflection.FieldAttributes.Family" /> ; that is, the field is visible only within its class and derived classes.
public bool
IsFamilyAndAssembly
Gets a value indicating whether the visibility of this field is described by <see cref="F:System.Reflection.FieldAttributes.FamANDAssem" /> ; that is, the field can be accessed from derived classes, but only if they are in the same assembly.
public bool
IsFamilyOrAssembly
Gets a value indicating whether the potential visibility of this field is described by <see cref="F:System.Reflection.FieldAttributes.FamORAssem" /> ; that is, the field can be accessed by derived classes wherever they are, and by classes in the same assembly.
public bool
IsInitOnly
Gets a value indicating whether the field can only be set in the body of the constructor.
public bool
IsLiteral
Gets a value indicating whether the value is written at compile time and cannot be changed.
public bool
IsNotSerialized
Gets a value indicating whether this field has the <see langword="NotSerialized" /> attribute.
public bool
IsPinvokeImpl
Gets a value indicating whether the corresponding <see langword="PinvokeImpl" /> attribute is set in <see cref="T:System.Reflection.FieldAttributes" /> .
public bool
IsPrivate
Gets a value indicating whether the field is private.
public bool
IsPublic
Gets a value indicating whether the field is public.
public bool
IsSecurityCritical
Gets a value that indicates whether the current field is security-critical or security-safe-critical at the current trust level.
public bool
IsSecuritySafeCritical
Gets a value that indicates whether the current field is security-safe-critical at the current trust level.
public bool
IsSecurityTransparent
Gets a value that indicates whether the current field is transparent at the current trust level.
public bool
IsSpecialName
Gets a value indicating whether the corresponding <see langword="SpecialName" /> attribute is set in the <see cref="T:System.Reflection.FieldAttributes" /> enumerator.
public bool
IsStatic
Gets a value indicating whether the field is static.
public MemberTypes
MemberType
Gets a <see cref="T:System.Reflection.MemberTypes" /> value indicating that this member is a field.
CustomAttributes
Gets a collection that contains this member's custom attributes.
public Type
DeclaringType
Gets the class that declares this member.
public bool
IsCollectible
Gets a value that indicates whether this <see cref="T:System.Reflection.MemberInfo" /> object references one or more assemblies held in a collectible <see cref="T:System.Runtime.Loader.AssemblyLoadContext" /> .
public int
MetadataToken
Gets a value that identifies a metadata element.
public Module
Module
Gets the module in which the type that declares the member represented by the current <see cref="T:System.Reflection.MemberInfo" /> is defined.
public string
Name
Gets the name of the current member.
public Type
ReflectedType
Gets the class object that was used to obtain this instance of <see langword="MemberInfo" /> .

Methods

public bool
Equals​(object obj)
obj An object to compare with this instance, or <see langword="null" /> .
Returns <see langword="true" /> if <paramref name="obj" /> equals the type and value of this instance; otherwise, <see langword="false" /> .
Returns a value that indicates whether this instance is equal to a specified object.
public int
GetHashCode​()
Returns A 32-bit signed integer hash code.
Returns the hash code for this instance.
public Type
GetModifiedFieldType​()
Returns A modified type.
Gets the modified type of this field object.
public Type[]
GetOptionalCustomModifiers​()
Returns An array of <see cref="T:System.Type" /> objects that identify the optional custom modifiers of the current field, such as <see cref="T:System.Runtime.CompilerServices.IsConst" /> .
Gets an array of types that identify the optional custom modifiers of the field.
public object
GetRawConstantValue​()
Returns An <see cref="T:System.Object" /> that contains the literal value associated with the field. If the literal value is a class type with an element value of zero, the return value is <see langword="null" /> .
Returns a literal value associated with the field by a compiler.
public Type[]
GetRequiredCustomModifiers​()
Returns An array of <see cref="T:System.Type" /> objects that identify the required custom modifiers of the current property, such as <see cref="T:System.Runtime.CompilerServices.IsConst" /> or <see cref="T:System.Runtime.CompilerServices.IsImplicitlyDereferenced" /> .
Gets an array of types that identify the required custom modifiers of the property.
public object
GetValue​(object obj)
obj The object whose field value will be returned.
Returns An object containing the value of the field reflected by this instance.
When overridden in a derived class, returns the value of a field supported by a given object.
public object
GetValueDirect​(TypedReference obj)
obj A <see cref="T:System.TypedReference" /> structure that encapsulates a managed pointer to a location and a runtime representation of the type that might be stored at that location.
Returns An <see langword="Object" /> containing a field value.
Returns the value of a field supported by a given object.
public void
SetValue​(object obj, object value)
obj The object whose field value will be set.
value The value to assign to the field.
Sets the value of the field supported by the given object.
public void
SetValue​(object obj, object value, BindingFlags invokeAttr, Binder binder, Globalization.CultureInfo culture)
obj The object whose field value will be set.
value The value to assign to the field.
invokeAttr A field of <see langword="Binder" /> that specifies the type of binding that is desired (for example, <see langword="Binder.CreateInstance" /> or <see langword="Binder.ExactBinding" /> ).
binder A set of properties that enables the binding, coercion of argument types, and invocation of members through reflection. If <paramref name="binder" /> is <see langword="null" /> , then <see langword="Binder.DefaultBinding" /> is used.
culture The software preferences of a particular culture.
When overridden in a derived class, sets the value of the field supported by the given object.
public void
SetValueDirect​(TypedReference obj, object value)
obj A <see cref="T:System.TypedReference" /> structure that encapsulates a managed pointer to a location and a runtime representation of the type that can be stored at that location.
value The value to assign to the field.
Sets the value of the field supported by the given object.
public object[]
GetCustomAttributes​(bool inherit)
Inherited from MemberInfo
inherit <see langword="true" /> to search this member's inheritance chain to find the attributes; otherwise, <see langword="false" /> . This parameter is ignored for properties and events.
Returns An array that contains all the custom attributes applied to this member, or an array with zero elements if no attributes are defined.
When overridden in a derived class, returns an array of all custom attributes applied to this member.
public object[]
GetCustomAttributes​(Type attributeType, bool inherit)
Inherited from MemberInfo
attributeType The type of attribute to search for. Only attributes that are assignable to this type are returned.
inherit <see langword="true" /> to search this member's inheritance chain to find the attributes; otherwise, <see langword="false" /> . This parameter is ignored for properties and events.
Returns An array of custom attributes applied to this member, or an array with zero elements if no attributes assignable to <paramref name="attributeType" /> have been applied.
When overridden in a derived class, returns an array of custom attributes applied to this member and identified by <see cref="T:System.Type" /> .
GetCustomAttributesData​()
Inherited from MemberInfo
Returns A generic list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target member.
Returns a list of <see cref="T:System.Reflection.CustomAttributeData" /> objects representing data about the attributes that have been applied to the target member.
public bool
HasSameMetadataDefinitionAs​(MemberInfo other)
Inherited from MemberInfo
public bool
IsDefined​(Type attributeType, bool inherit)
Inherited from MemberInfo
attributeType The type of custom attribute to search for. The search includes derived types.
inherit <see langword="true" /> to search this member's inheritance chain to find the attributes; otherwise, <see langword="false" /> . This parameter is ignored for properties and events.
Returns <see langword="true" /> if one or more instances of <paramref name="attributeType" /> or any of its derived types is applied to this member; otherwise, <see langword="false" /> .
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.
protected void
Finalize​()
Inherited from object
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
public Type
GetType​()
Inherited from object
Returns The exact runtime type of the current instance.
Gets the <see cref="T:System.Type" /> of the current instance.
protected object
MemberwiseClone​()
Inherited from object
Returns A shallow copy of the current <see cref="T:System.Object" /> .
Creates a shallow copy of the current <see cref="T:System.Object" /> .
public string
ToString​()
Inherited from object
Returns A string that represents the current object.
Returns a string that represents the current object.