Export (0) Print
Expand All

FieldInfo.IsSpecialName Property

Gets a value indicating whether the corresponding SpecialName attribute is set in the FieldAttributes enumerator.

[Visual Basic]
Public ReadOnly Property IsSpecialName As Boolean
[C#]
public bool IsSpecialName {get;}
[C++]
public: __property bool get_IsSpecialName();
[JScript]
public function get IsSpecialName() : Boolean;

Property Value

true if the SpecialName attribute is set in FieldAttributes; otherwise, false.

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.

Example

[Visual Basic, C#, C++] The following example returns a value indicating whether or not the fields in the class contain a SpecialName attribute.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.ComponentModel.Design
Imports Microsoft.VisualBasic

Class FieldInfo_IsSpecialName

    Public Shared Sub Main()
        Try
            ' Get the type handle of a specified class.
            Dim myType As Type = GetType(ViewTechnology)

            ' Get the fields of a specified class.
            Dim myField As FieldInfo() = myType.GetFields()

            Console.WriteLine(ControlChars.Cr + "Displaying fields that have SpecialName attributes:" + ControlChars.Cr)
            Dim i As Integer
            For i = 0 To myField.Length - 1
                ' Determine whether or not each field is a special name.
                If myField(i).IsSpecialName Then
                    Console.WriteLine("The field {0} has a SpecialName attribute.", myField(i).Name)
                End If
            Next i
        Catch e As Exception
            Console.WriteLine("Exception : {0} ", e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'FieldInfo_IsSpecialName

[C#] 
using System;
using System.Reflection;
using System.ComponentModel.Design;


class FieldInfo_IsSpecialName
{
    public static void Main()
    {     
        try
        {
            // Get the type handle of a specified class.
            Type myType = typeof(ViewTechnology);
         
            // Get the fields of the specified class.
            FieldInfo[] myField = myType.GetFields();

            Console.WriteLine("\nDisplaying fields that have SpecialName attributes:\n");
            for(int i = 0; i < myField.Length; i++)
            {
                // Determine whether or not each field is a special name.
                if(myField[i].IsSpecialName)
                {
                    Console.WriteLine("The field {0} has a SpecialName attribute.",
                        myField[i].Name);
                }
            }
        }
        catch(Exception e)
        {
            Console.WriteLine("Exception : {0} " , e.Message);
        }
    }
}

[C++] 
#using <mscorlib.dll>
#using <system.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::ComponentModel::Design;

int main()
{     
   try {
      // Get the type handle of a specified class.
      Type* myType = __typeof(ViewTechnology);

      // Get the fields of the specified class.
      FieldInfo* myField[] = myType->GetFields();

      Console::WriteLine(S"\nDisplaying fields that have SpecialName attributes:\n");
      for (int i = 0; i < myField->Length; i++) {
         // Determine whether or not each field is a special name.
         if (myField[i]->IsSpecialName) {
            Console::WriteLine(S"The field {0} has a SpecialName attribute.",
               myField[i]->Name);
         }
      }
   } catch (Exception* e) {
      Console::WriteLine(S"Exception : {0} " , e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

FieldInfo Class | FieldInfo Members | System.Reflection Namespace | FieldAttributes

Show:
© 2014 Microsoft