MethodBase.IsPublic MethodBase.IsPublic MethodBase.IsPublic MethodBase.IsPublic Property

定義

パブリック メソッドかどうかを示す値を取得します。Gets a value indicating whether this is a public method.

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

プロパティ値

このメソッドがパブリックの場合は true。それ以外の場合は falsetrue if this method is public; otherwise, false.

実装

次の例では、IsPublicプロパティを指定されたメソッドがパブリックかどうかを示すメッセージを表示します。The following example uses the IsPublic property to display a message that indicates whether the specified method is public.

int main()
{
   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", static_cast<BindingFlags>(BindingFlags::NonPublic | BindingFlags::Instance) );
   Console::Write( "\nMymethodbase = {0}", 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
*/
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
*/
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 

注釈

取得する、 MethodBase、まず、型を取得します。To get the MethodBase, first get the type. 型からメソッドを取得します。From the type, get the method. メソッドから取得、MethodBaseします。From the method, get the MethodBase. 場合、MethodBaseコンス トラクターはパブリック以外、またはが保護されているし、すぐにアクセスすることはできません。If the MethodBase or constructor is other than public, it is protected and cannot be readily accessed. 非パブリック メソッドにアクセスするには、設定、BindingFlagsマスクをNonPublicGetMethodします。To access a non-public method, set the BindingFlags mask to NonPublic in GetMethod.

適用対象

こちらもご覧ください