Exporter (0) Imprimer
Développer tout
Développer Réduire

MethodBase.IsSpecialName, propriété

Obtient une valeur indiquant si cette méthode est dotée d'un nom spécial.

Espace de noms : System.Reflection
Assembly : mscorlib (dans mscorlib.dll)

public bool IsSpecialName { get; }
/** @property */
public final boolean get_IsSpecialName ()

public final function get IsSpecialName () : boolean

Valeur de la propriété

true si cette méthode est dotée d'un nom spécial ; sinon false.

Le bit SpecialName est défini pour signaler des membres traités de manière spécifique par certains compilateurs (par exemple, les accesseurs de propriété et les méthodes de surcharge d'opérateur).

Cet exemple illustre une utilisation de IsSpecialName pour filtrer les membres internes ou privés hors d'une liste.

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

import System.*;
import System.IO.*;
import System.Reflection.*;
import System.Text.*;

public class Sample
{
    protected boolean showMethods;
    protected StreamWriter myWriter;

    private void DumpMethods(Type aType)
    {
        if (!(showMethods)) {
            return ;
        }
        MethodInfo mInfo[] = aType.GetMethods();
        myWriter.WriteLine("Methods");
        boolean 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].get_DeclaringType().Equals(aType) &&
                    !(mInfo[i].get_IsSpecialName()) ) {
                        found = true;
                        StringBuilder modifiers = new StringBuilder();
                        if ( mInfo[i].get_IsStatic() ) {
                            modifiers.Append("static ");
                        }
                        if ( mInfo[i].get_IsPublic() ) {
                            modifiers.Append("public ");
                        }
                        if ( mInfo[i].get_IsFamily() ) {
                            modifiers.Append("protected ");
                        }
                        if ( mInfo[i].get_IsAssembly()) {
                            modifiers.Append("internal ");
                        }
                        if ( mInfo[i].get_IsPrivate() ) {
                            modifiers.Append("private ");
                        }
                        myWriter.WriteLine("{0} {1}", 
                            modifiers, mInfo.get_Item(i));
                }
            } 
        }
        if (!(found) ) {
            myWriter.WriteLine("(none)");
        }
    } //DumpMethods
} //Sample

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 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0

.NET Compact Framework

Prise en charge dans : 2.0, 1.0

Ajouts de la communauté

AJOUTER
Afficher:
© 2015 Microsoft