FieldInfo.IsSpecialName Property【转】

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

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

public bool IsSpecialName { get; }

Property Value

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

Implements

_FieldInfo.IsSpecialName

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 returns a value indicating whether or not the fields in the class contain a SpecialName attribute.

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("
Displaying fields that have SpecialName attributes:
");
            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);
        }
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

原文地址:https://www.cnblogs.com/zhouyunbaosujina/p/3292149.html