Partager via


FieldInfo.IsSpecialName Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public ReadOnly Property IsSpecialName As Boolean
public bool IsSpecialName { get; }

Property Value

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

Exceptions

Exception Condition
MethodAccessException

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

Remarks

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.

Examples

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

Imports System.Reflection

Class Example

    Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

        Dim myType As Type = GetType(EventAttributes)

        outputBlock.Text = _
            String.Format("Fields of {0}, flagging FieldAttributes.SpecialName:" & vbLf, _
                          myType.Name)

        For Each fi As FieldInfo in myType.GetFields()
            ' Determine whether or not each field has a special name.
            If fi.IsSpecialName Then
                outputBlock.Text &= _
                    String.Format("{0} has the FieldAttributes.SpecialName attribute." & vbLf, _
                                  fi.Name)
            Else
                outputBlock.Text &= fi.Name & vbLf
            End If
        Next fi

    End Sub 

End Class 

' This example produces output similar to the following:
'
'Fields of EventAttributes, flagging FieldAttributes.SpecialName:
'value__ has the FieldAttributes.SpecialName attribute.
'None
'SpecialName
'ReservedMask
'RTSpecialName
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
 */

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.