A System.Reflection.FieldAttributes value that indicates the attributes of the field reflected by the current instance.
All members have a set of attributes, which are defined in relation to the specific type of member. FieldAttributes informs the user whether this field is the private field, a static field, and so on.
To get the Attributes property, first get the class Type. From the Type, get the FieldInfo. From the FieldInfo, get the Attributes.
The following example demonstrates obtaining the attributes of two fields.
C# Example
using System; using System.Reflection; class MyClass { public int MyPublicInstanceField; private const int MyPrivateConstField = 10; } class FieldAttributesExample { public static void Main() { Type t = (typeof(MyClass)); string str; FieldInfo[] fiAry = t.GetFields( BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly ); foreach (FieldInfo fi in fiAry) { Console.WriteLine("Field {0} is: ", fi.Name); str = ((fi.Attributes & FieldAttributes.Static) != 0) ? "Static" : "Instance"; Console.Write(str + " "); str = ((fi.Attributes & FieldAttributes.Public) != 0) ? "Public" : "Not-Public"; Console.Write(str + " "); str = ((fi.Attributes & FieldAttributes.Literal) != 0) ? "Literal" : String.Empty; Console.WriteLine(str); } } }
The output is
Field MyPublicInstanceField is: