共用方式為


MethodBase.IsSpecialName 屬性

定義

取得值,指出這個方法是否有特別的名稱。

public:
 property bool IsSpecialName { bool get(); };
public bool IsSpecialName { get; }
member this.IsSpecialName : bool
Public ReadOnly Property IsSpecialName As Boolean

屬性值

如果這個方法有特別的名稱,則為 true,否則為 false

實作

範例

此範例示範 如何使用 IsSpecialName 來篩選出清單的內部或私人成員。

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Text;
public ref class Sample
{
protected:
   bool ShowMethods;
   StreamWriter^ myWriter;

private:
   void DumpMethods( Type^ aType )
   {
      if (  !ShowMethods )
            return;

      array<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 = gcnew 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)" );
      }
   }

};
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)");
        }
    }
}
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

備註

SpecialName 設定為標幟某些編譯程式以特殊方式處理的成員, (例如屬性存取子和運算元多載方法) 。

適用於

另請參閱