次の方法で共有


Type.IsSpecialName プロパティ

Type の名前が特別な処理を必要とするかどうかを示す値を取得します。

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

プロパティ値

Type の名前が特別な処理を必要とする場合は true 。それ以外の場合は false

解説

アンダースコア (_)、プロパティ アクセサ、メソッドをオーバーロードする演算子などで始まるか、それらを含む名前の型は、一部のコンパイラでは特別な処理が必要になります。

使用例

IsSpecialName を使用して、内部メンバまたはプライベート メンバをリストから抽出するコード例を次に示します。

 
Imports System
Imports System.IO
Imports System.Reflection
Imports System.Text
Public Class Sample
    Protected ShowMethods As Boolean
    Protected myWriter As StreamWriter
    Private Sub DumpMethods(ByVal aType As Type)
        If Not ShowMethods Then
            Return
        End If
        Dim mInfo As MethodInfo() = aType.GetMethods()
        myWriter.WriteLine("Methods")
        Dim found As Boolean = False
        If mInfo.Length <> 0 Then
            Dim i As Integer
            For i = 0 To mInfo.Length - 1
                ' Only display methods declared in this type. Also 
                ' filter out any methods with special names, because these
                ' cannot be generally called by the user. That is, their 
                ' functionality is usually exposed in other ways, for example,
                ' property get/set methods are exposed as properties.
                If mInfo(i).DeclaringType Is aType _
                   And Not mInfo(i).IsSpecialName Then
                    found = True
                    Dim modifiers As New StringBuilder()
                    If mInfo(i).IsStatic Then
                        modifiers.Append("static ")
                    End If
                    If mInfo(i).IsPublic Then
                        modifiers.Append("public ")
                    End If
                    If mInfo(i).IsFamily Then
                        modifiers.Append("protected ")
                    End If
                    If mInfo(i).IsAssembly Then
                        modifiers.Append("internal ")
                    End If
                    If mInfo(i).IsPrivate Then
                        modifiers.Append("private ")
                    End If
                    myWriter.WriteLine("{0} {1}", modifiers, mInfo(i))
                End If
            Next i
        End If
        If Not found Then
            myWriter.WriteLine("(none)")
        End If
    End Sub
End Class

[C#] 
using System;
using System.IO;
using System.Reflection;
using System.Text;

public class Sample
{
    protected bool ShowMethods;
    protected StreamWriter myWriter;
 
    private void DumpMethods(Type aType)
    {
        if (!ShowMethods)
            return;
        MethodInfo[] mInfo = aType.GetMethods();
        myWriter.WriteLine("Methods"); 
        bool found = false;            
        if (mInfo.Length != 0)
        {
            for (int i=0; i < mInfo.Length; i++)
            {
                // Only display methods declared in this type. Also 
                // filter out any methods with special names, because these
                // cannot be generally called by the user. That is, their 
                // functionality is usually exposed in other ways, for example,
                // property get/set methods are exposed as properties.
                if (mInfo[i].DeclaringType == aType && !mInfo[i].IsSpecialName)
                {        
                    found = true;
                    StringBuilder modifiers = new StringBuilder();
                    if (mInfo[i].IsStatic)   {modifiers.Append("static ");}     
                    if (mInfo[i].IsPublic)   {modifiers.Append("public ");}     
                    if (mInfo[i].IsFamily)   {modifiers.Append("protected ");}     
                    if (mInfo[i].IsAssembly) {modifiers.Append("internal ");}     
                    if (mInfo[i].IsPrivate)  {modifiers.Append("private ");}     
                    myWriter.WriteLine("{0} {1}", modifiers, mInfo[i]);
                }
            }                      
        }                    
        if (!found)
        {
            myWriter.WriteLine("(none)");
        }
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Text;

public __gc class Sample
{
protected:
    bool ShowMethods;
    StreamWriter* myWriter;
 
private:
    void DumpMethods(Type* aType)
    {
        if (!ShowMethods)
            return;
        MethodInfo* mInfo[] = aType->GetMethods();
        myWriter->WriteLine(S"Methods"); 
        bool found = false;            
        if (mInfo->Length != 0)
        {
            for (int i=0; i < mInfo->Length; i++)
            {
                // Only display methods declared in this type. Also 
                // filter out any methods with special names, because these
                // cannot be generally called by the user. That is, their 
                // functionality is usually exposed in other ways, for example,
                // property get/set methods are exposed as properties.
                if (mInfo[i]->DeclaringType == aType && !mInfo[i]->IsSpecialName)
                {        
                    found = true;
                    StringBuilder* modifiers = new StringBuilder();
                    if (mInfo[i]->IsStatic)   {modifiers->Append(S"static ");}     
                    if (mInfo[i]->IsPublic)   {modifiers->Append(S"public ");}     
                    if (mInfo[i]->IsFamily)   {modifiers->Append(S"protected ");}     
                    if (mInfo[i]->IsAssembly) {modifiers->Append(S"internal ");}     
                    if (mInfo[i]->IsPrivate)  {modifiers->Append(S"private ");}     
                    myWriter->WriteLine(S"{0} {1}",modifiers,mInfo[i]);
                }
            }                      
        }                    
        if (!found)
        {
            myWriter->WriteLine(S"(none)");
        }
    }
};

[JScript] 
private function DumpMethods(aType : Type) : void 
 {
 if (!ShowMethods)
 return;
 var mInfo : MethodInfo[] = aType.GetMethods();
 myWriter.WriteLine("Methods"); 
 var found : boolean = false;            
 
   if (mInfo.Length != 0)
   {
    for ( var i:int =0; i < mInfo.Length; i++ )
    {
    // Only display methods declared in this type. Also 
    // filter out any methods with special names, because these
    // cannot be generally called by the user. That is, their 
    // functionality is usually exposed in other ways, for example,
    // property get/set methods are exposed as properties.
             
     if (mInfo[i].DeclaringType.Equals(aType) && !mInfo[i].IsSpecialName)
     {        
      found = true;
      var modifiers : StringBuilder = new StringBuilder();
      if (mInfo[i].IsStatic)   {modifiers.Append("static ");}     
      if (mInfo[i].IsPublic)   {modifiers.Append("public ");}     
      if (mInfo[i].IsFamily)   {modifiers.Append("protected ");}     
      if (mInfo[i].IsAssembly) {modifiers.Append("internal ");}     
      if (mInfo[i].IsPrivate)  {modifiers.Append("private ");}     
    myWriter.WriteLine("{0} {1}", [modifiers, mInfo[i]]);
      }
    }                      
  }                    
      if (!found)
      {
       myWriter.WriteLine("(none)");
      }
 }

必要条件

プラットフォーム: 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, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | TypeAttributes