Export (0) Print
Expand All

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

Not applicable.

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.

The following example uses the IsPublic property to display a message that indicates whether the specified method is public.

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 Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft