Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

MethodBase.IsPublic Property

Gets a value indicating whether this is a public method.

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

'Declaration
Public ReadOnly Property IsPublic As Boolean

Property Value

Type: System.Boolean
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 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 

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft