IsPublic Property

MethodBase.IsPublic Property

Gets a value that indicates whether this is a public method.

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

'Declaration
Public ReadOnly Property IsPublic As Boolean

Property Value

Type: System.Boolean
true if this method is public; otherwise, false.

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


Imports System.Reflection
Imports System.Collections.Generic

Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) 

      Dim instanceAll As BindingFlags = BindingFlags.Public Or _
         BindingFlags.NonPublic Or BindingFlags.Instance

      Dim t As Type = GetType(Example)
      Dim ctorsAndMethods As New List(Of MethodBase)( _
         t.GetMethods(instanceAll))

      For Each c As ConstructorInfo In t.GetConstructors(instanceAll)
         ctorsAndMethods.Add(c)
      Next

      outputBlock.Text &= "Public?      Method or Constructor Description" & vbLf 

      For Each m As MethodBase In ctorsAndMethods 
         outputBlock.Text &= String.Format(" {0,-6}      {1}" & vbLf, _
            m.IsPublic, m.ToString())
      Next

   End Sub

   ' Example constructors.
   '
   Private Sub New() 
   End Sub

   Protected Sub New(ByVal int As Integer)
   End Sub

   Public Sub New(ByVal name As String)
   End Sub

End Class

' This example produces the following output:
' 
'Public?    Method or Constructor Description
' True      System.String ToString()
' True      Boolean Equals(System.Object)
' True      Int32 GetHashCode()
' True      System.Type GetType()
' False     Void Finalize()
' False     System.Object MemberwiseClone()
' False     Void .ctor()
' False     Void .ctor(Int32)
' True      Void .ctor(System.String)


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show:
© 2016 Microsoft