対応する SpecialName 属性が FieldAttributes 列挙子に設定されているかどうかを示す値を取得します。
Public ReadOnly Property IsSpecialName As Boolean
[C#]
public bool IsSpecialName {get;}
[C++]
public: __property bool get_IsSpecialName();
[JScript]
public function get IsSpecialName() : Boolean;
プロパティ値
FieldAttributes に SpecialName 属性が設定されている場合は true 。それ以外の場合は false 。
解説
アンダースコア (_)、プロパティ アクセサ、メソッドをオーバーロードする演算子などで始まるか、それらを含む名前は、一部のコンパイラでは特別な処理が必要になります。
使用例
[Visual Basic, C#, C++] クラスのフィールドが SpecialName 属性を持っているかどうかを示す値を返す例を次に示します。
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
参照
FieldInfo クラス | FieldInfo メンバ | System.Reflection 名前空間 | FieldAttributes