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.

Namespace: System.Reflection
Assembly: mscorlib (in mscorlib.dll)

public bool IsPublic { get; }
/** @property */
public final boolean get_IsPublic ()

public final function get IsPublic () : boolean

Property Value

true if this method is public; otherwise, false.

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.

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 Methodbase
{
    public static void 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));
        boolean myIsPublic = myMethodBase.get_IsPublic();
        if (myIsPublic) {
            Console.Write("\nmyMethodBase is a public method");
        }
        else {
            Console.Write("\nmyMethodBase is not a public method");
        }
    } //main
} //Methodbase

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

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

Show:
© 2014 Microsoft