次の方法で共有


MethodBase.IsPublic プロパティ

パブリック メソッドかどうかを示す値を取得します。

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

プロパティ値

このメソッドがパブリックの場合は true 。それ以外の場合は false

解説

MethodBase を取得するには、最初に型を取得します。型からメソッドを取得します。メソッドから MethodBase を取得します。 MethodBase またはコンストラクタがパブリックでない場合は、それらは保護されているため簡単にはアクセスできません。パブリックでないメソッドにアクセスするには、 GetMethodBindingFlags マスクを NonPublic に設定します。

使用例

 
Class methodbase1
    
    Public Shared Function Main() As Integer
    
        Console.WriteLine(ControlChars.Cr + "Reflection.MethodBase")
        
        'Get the MethodBase of a method.
        
        'Get the type
        Dim MyType As Type = Type.GetType("System.MulticastDelegate")
        
        'Get and display the method
        Dim Mymethodbase As MethodBase = _
           MyType.GetMethod("RemoveImpl", BindingFlags.NonPublic)
        
        Console.Write(ControlChars.Cr _
           + "Mymethodbase = " + Mymethodbase.ToString())
        
        Dim Myispublic As Boolean = Mymethodbase.IsPublic
        If Myispublic Then
            Console.Write(ControlChars.Cr _
               + "Mymethodbase is a public method")
        Else
            Console.Write(ControlChars.Cr _
               + "Mymethodbase is not a public method")
        End If 
        Return 0
    End Function
End Class

' Produces the following output
' 
' Reflection.MethodBase
' Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
' Mymethodbase is not a public method 

[C#] 
class methodbase
{
   public static int Main(string[] args)
   {     

      Console.WriteLine("\nReflection.MethodBase");
      
      //Get the MethodBase of a method.
 
      //Get the type
      Type MyType = Type.GetType("System.MulticastDelegate");
 
      //Get and display the method
      MethodBase Mymethodbase =
         MyType.GetMethod("RemoveImpl",BindingFlags.NonPublic);
 
      Console.Write("\nMymethodbase = " + Mymethodbase);
 
      bool Myispublic = Mymethodbase.IsPublic;
      if (Myispublic)
         Console.Write ("\nMymethodbase is a public method");
      else
         Console.Write ("\nMymethodbase is not a public method");
      
      return 0;
   }
}
/*
Produces the following output

Reflection.MethodBase
Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
Mymethodbase is not a public method
*/

[C++] 
int main()
{     

    Console::WriteLine(S"\nReflection.MethodBase");

    //Get the MethodBase of a method.

    //Get the type
    Type* MyType = Type::GetType(S"System.MulticastDelegate");

    //Get and display the method
    MethodBase* Mymethodbase =
        MyType->GetMethod(S"RemoveImpl",
            static_cast<BindingFlags>(BindingFlags::NonPublic|BindingFlags::Instance));

    Console::Write(S"\nMymethodbase = {0}", Mymethodbase);

    bool Myispublic = Mymethodbase->IsPublic;
    if (Myispublic)
        Console::Write (S"\nMymethodbase is a public method");
    else
        Console::Write (S"\nMymethodbase is not a public method");

    return 0;
}
/*
Produces the following output

Reflection.MethodBase
Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
Mymethodbase is not a public method
*/

[JScript] 
class methodbase
{
   public static function Main() : void 
   {     

      Console.WriteLine("\nReflection.MethodBase");
      
      //Get the MethodBase of a method.
 
      //Get the type
      var MyType : Type = Type.GetType("System.MulticastDelegate");
 
      //Get and display the method
      var Mymethodbase : MethodBase =
         MyType.GetMethod("RemoveImpl",BindingFlags.NonPublic|BindingFlags.Instance);
 
      Console.Write("\nMymethodbase = " + Mymethodbase);
 
      var Myispublic : boolean = Mymethodbase.IsPublic;
      if (Myispublic)
         Console.Write ("\nMymethodbase is a public method");
      else
         Console.Write ("\nMymethodbase is not a public method");
   }
}
methodbase.Main();
/*
Produces the following output

Reflection.MethodBase
Mymethodbase = System.Delegate RemoveImpl (System.Delegate)
Mymethodbase is not a public method
*/

必要条件

プラットフォーム: 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

参照

MethodBase クラス | MethodBase メンバ | System.Reflection 名前空間 | Boolean | BindingFlags