Name

FieldInfo

Synopsis

This class is an implementation of MemberInfo and allows access to an instance field. Note that, like all reflective objects, the FieldInfo instance refers to the metadata concept of the field within the type, not a particular field within a particular instance of that type. (This is important when working with or manipulating the value stored in object instance fields.)

IsAssembly, IsFamily, IsFamilyAndAssembly, IsFamilyOrAssembly, IsPublic, and IsPrivate allow you to check the visibility of the field. FieldType returns the declared type of this field. FieldHandle is a System.RuntimeFieldHandle. Use Attributes to retrieve the attributes. To see if the FieldInfo has the NotSerialized or PinvokeImplFieldAttributes set, inspect the IsNotSerialized and IsPinvokeImpl properties. If the field is static, IsStatic is true. The Set and Get methods allow you set the values, and the ones with Direct in their name take a typed reference as opposed to an object.

public abstract class FieldInfo : MemberInfo {
// Protected Constructors
   protected FieldInfo( );
// Public Instance Properties
   public abstract FieldAttributes Attributes{get; }
   public abstract RuntimeFieldHandle FieldHandle{get; }
   public abstract Type FieldType{get; }
   public bool IsAssembly{get; }
   public bool IsFamily{get; }
   public bool IsFamilyAndAssembly{get; }
   public bool IsFamilyOrAssembly{get; }
   public bool IsInitOnly{get; }
   public bool IsLiteral{get; }
   public bool IsNotSerialized{get; }
   public bool IsPinvokeImpl ...

Get C# in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.