FieldInfo.IsSpecialName Property

July 28, 2014

Gets a value that indicates whether the field has a name that has special significance.

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

public bool IsSpecialName { get; }

Property Value

Type: System.Boolean
true if the field has the FieldAttributes.SpecialName attribute set; otherwise, false.

ExceptionCondition
MethodAccessException

This member is invoked late-bound through mechanisms such as Type.InvokeMember.

Names that begin with or contain an underscore character (_), property accessors, and operator overloading methods are examples of names that might require special treatment by some compilers.

The following example shows whether or not the fields in the class have the FieldAttributes.SpecialName attribute.


using System;
using System.Reflection;

class Example
{
    public static void Demo(System.Windows.Controls.TextBlock outputBlock)
    {
        Type myType = typeof(EventAttributes);

        outputBlock.Text = 
            String.Format("Fields of {0}, flagging FieldAttributes.SpecialName:\n",
                          myType.Name);

        foreach (FieldInfo fi in myType.GetFields())
        {
            // Determine whether or not each field has a special name.
            if (fi.IsSpecialName)
            {
                outputBlock.Text += 
                    String.Format("{0} has the FieldAttributes.SpecialName attribute.\n", 
                                  fi.Name);
            }
            else
            {
                outputBlock.Text += fi.Name + "\n";
            }
        }
    }
}

/* This example produces output similar to the following:

Fields of EventAttributes, flagging FieldAttributes.SpecialName:
value__ has the FieldAttributes.SpecialName attribute.
None
SpecialName
ReservedMask
RTSpecialName
 */


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft