GetGetMethod Method (Boolean)
Collapse the table of content
Expand the table of content

PropertyInfo.GetGetMethod Method (Boolean)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

When overridden in a derived class, returns the public or non-public get accessor for this property.

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

'Declaration
Public MustOverride Function GetGetMethod ( _
	nonPublic As Boolean _
) As MethodInfo

Parameters

nonPublic
Type: System.Boolean
true to return a non-public accessor; otherwise, false.

Return Value

Type: System.Reflection.MethodInfo
The get accessor for this property, if nonPublic is true. Returns Nothing if nonPublic is false and the get accessor is non-public, or if nonPublic is true but no get accessor exists.

ExceptionCondition
MethodAccessException

Application code attempts to access this member late-bound, for example by using the Type.InvokeMember method.

This property is the MethodInfo representing the get accessor.

To use the GetGetMethod method, first get the class Type. From the Type, get the PropertyInfo. From the PropertyInfo, use the GetGetMethod method.

The following example demonstrates both overloads of the GetGetMethod method. The example defines a public property and a protected property. The example uses the GetGetMethod and GetGetMethod(Boolean) method overloads to display the get accessors of both properties. In the first case, only the get accessor for the public property is displayed.


Imports System.Reflection

Class Example

   ' Define properties with different access levels.

   Private myCaption As String = "A Default caption"
   Public ReadOnly Property Caption() As String
      Get
         Return myCaption
      End Get
   End Property

   Private myText As String = "Default text."
   Protected ReadOnly Property Text() As String
      Get
         Return myText
      End Get
   End Property


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

      ' Get the PropertyInfo objects.
      Dim captionInfo As PropertyInfo = GetType(Example).GetProperty("Caption")
      Dim textInfo As PropertyInfo = _
         GetType(Example).GetProperty("Text", _
                                      BindingFlags.NonPublic Or BindingFlags.Instance)

      outputBlock.Text &= "Public get accessors:" & vbLf

      ' List the public get accessors.
      Dim publicGetAccessors() As MethodInfo = { captionInfo.GetGetMethod(), _
                                                 textInfo.GetGetMethod() }

      For Each mi As MethodInfo In publicGetAccessors
         If mi Is Nothing Then
            outputBlock.Text &= "No get accessor was found." & vbLf
         Else
            outputBlock.Text &= mi.ToString() & vbLf
         End If
      Next

      outputBlock.Text &= vbLf & "All get accessors:" & vbLf

      ' List all get accessors.
      Dim allGetAccessors() As MethodInfo = { captionInfo.GetGetMethod(True), _
                                              textInfo.GetGetMethod(True) }

      For Each mi As MethodInfo In allGetAccessors
         If mi Is Nothing Then
            outputBlock.Text &= "No get accessor was found." & vbLf
         Else
            outputBlock.Text &= mi.ToString() & vbLf
         End If
      Next

   End Sub
End Class

' This example produces the following output:
'
'Public get accessors:
'System.String get_Caption()
'No get accessor was found.
'
'All get accessors:
'System.String get_Caption()
'System.String get_Text()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft