Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MethodBase.IsPublic Property

Gets a value indicating whether this is a public method.

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

Property Value

true if this method is public; otherwise, false.

Remarks

To get the MethodBase, first get the type. From the type, get the method. From the method, get the MethodBase. If the MethodBase or constructor is other than public, it is protected and cannot be readily accessed. To access a non-public method, set the BindingFlags mask to NonPublic in GetMethod.

Example

[Visual Basic] 
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
*/

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

MethodBase Class | MethodBase Members | System.Reflection Namespace | Boolean | BindingFlags

Show:
© 2014 Microsoft