Windows apps
Collapse the table of content
Expand the table of content
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.

PropertyInfo.GetGetMethod Method (Boolean)

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)

public abstract MethodInfo GetGetMethod (
	bool nonPublic
)
public abstract MethodInfo GetGetMethod (
	boolean nonPublic
)
public abstract function GetGetMethod (
	nonPublic : boolean
) : MethodInfo

Parameters

nonPublic

Indicates whether a non-public get accessor should be returned. true if a non-public accessor is to be returned; otherwise, false.

Return Value

A MethodInfo object representing the get accessor for this property, if nonPublic is true. Returns a null reference (Nothing in Visual Basic) if nonPublic is false and the get accessor is non-public, or if nonPublic is true but no get accessors exist.

Exception typeCondition

SecurityException

The requested method is non-public and the caller does not have ReflectionPermission to reflect on this non-public 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 displays the public or non-public get accessor for the specified property.

using System;
using System.Reflection;
 
// Define a property.
public class Myproperty   
{
    private string caption = "A Default caption";
    public string Caption
    {
        get{return caption;}
        set {if(caption!=value) {caption = value;}
        }
    }
}
 
class Mypropertyinfo
{
    public static int Main()
    {
        Console.WriteLine ("\nReflection.PropertyInfo");
 
        // Get the type and PropertyInfo for two separate properties.
        Type MyTypea = Type.GetType("Myproperty");
        PropertyInfo Mypropertyinfoa = MyTypea.GetProperty("Caption");
        Type MyTypeb = Type.GetType("System.Reflection.MethodInfo");
        PropertyInfo Mypropertyinfob = MyTypeb.GetProperty("MemberType");
 
        // Get and display the GetGetMethod method for each property.
        MethodInfo Mygetmethodinfoa = Mypropertyinfoa.GetGetMethod();
        Console.Write ("\nGetAccessor for " + Mypropertyinfoa.Name
            + " returns a " + Mygetmethodinfoa.ReturnType);
        MethodInfo Mygetmethodinfob = Mypropertyinfob.GetGetMethod();
        Console.Write ("\nGetAccessor for " + Mypropertyinfob.Name
            + " returns a " + Mygetmethodinfob.ReturnType);
 
        // Display the GetGetMethod without using the MethodInfo.
        Console.Write ("\n" + MyTypea.FullName + "." + Mypropertyinfoa.Name
            + " GetGetMethod - " + Mypropertyinfoa.GetGetMethod());
        Console.Write ("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name
            + " GetGetMethod - " + Mypropertyinfob.GetGetMethod());
        return 0;
    }
}

import System.*;
import System.Reflection.*;

// Define a property.
public class MyProperty
{
    private String caption = "A Default caption";

    /** @property 
     */
    public String get_Caption()
    {
        return caption ;
    } //get_Caption

    /** @property 
     */
    public void set_Caption (String value)
    {
        if (caption != value) {
            caption = value;
        }
    } //set_Caption
} //MyProperty

class MyPropertyInfo
{   
    public static void main(String[] args)
    {
        Console.WriteLine("\nReflection.PropertyInfo");

        // Get the type and PropertyInfo for two separate properties.
        Type myTypeA = Type.GetType("MyProperty");
        PropertyInfo myPropertyInfoA = myTypeA.GetProperty("Caption");
        Type myTypeB = Type.GetType("System.Reflection.MethodInfo");
        PropertyInfo myPropertyInfoB = myTypeB.GetProperty("MemberType");

        // Get and display the GetGetMethod method for each property.
        MethodInfo myGetmethodInfoA = myPropertyInfoA.GetGetMethod();
        Console.Write(("\nGetAccessor for " + myPropertyInfoA.get_Name() 
            + " returns a " + myGetmethodInfoA.get_ReturnType()));
        MethodInfo myGetmethodInfoB = myPropertyInfoB.GetGetMethod();
        Console.Write(("\nGetAccessor for " + myPropertyInfoB.get_Name() 
            + " returns a " + myGetmethodInfoB.get_ReturnType()));

        // Display the GetGetMethod without using the MethodInfo.
        Console.Write(("\n" + myTypeA.get_FullName() + "." 
            + myPropertyInfoA.get_Name() + " GetGetMethod - " 
            + myPropertyInfoA.GetGetMethod()));
        Console.Write(("\n" + myTypeB.get_FullName() + "." 
            + myPropertyInfoB.get_Name() + " GetGetMethod - " 
            + myPropertyInfoB.GetGetMethod()));
    } //main
} //MyPropertyInfo

 import System;
 import System.Reflection;
 
 //Make a property
 public class Myproperty   
 {
    private var caption : String = "A Default caption";
    public function get Caption() : String {
        return caption;
    }
    public function set Caption(value:String) {
        if(caption!=value) caption = value;
    }
 }
 
 class Mypropertyinfo
 {
    public static function Main() : void
       {
       Console.WriteLine ("\nReflection.PropertyInfo");
 
       //Get the type and PropertyInfo for two separate properties
       var MyTypea : Type = Type.GetType("Myproperty");
       var Mypropertyinfoa : PropertyInfo = MyTypea.GetProperty("Caption");
       var MyTypeb : Type = Type.GetType("System.Reflection.MethodInfo");
       var Mypropertyinfob : PropertyInfo = MyTypeb.GetProperty("MemberType");
 
       //Get and display the GetGetMethod Method for each property
       var Mygetmethodinfoa : MethodInfo = Mypropertyinfoa.GetGetMethod();
       Console.Write ("\nGetAccessor for " + Mypropertyinfoa.Name
          + " returns a " + Mygetmethodinfoa.ReturnType);
       var Mygetmethodinfob : MethodInfo = Mypropertyinfob.GetGetMethod();
       Console.Write ("\nGetAccessor for " + Mypropertyinfob.Name
          + " returns a " + Mygetmethodinfob.ReturnType);
 
       //Display the GetGetMethod without using the MethodInfo
       Console.Write ("\n" + MyTypea.FullName + "." + Mypropertyinfoa.Name
           + " GetGetMethod - " + Mypropertyinfoa.GetGetMethod());
       Console.Write ("\n" + MyTypeb.FullName + "." + Mypropertyinfob.Name
           + " GetGetMethod - " + Mypropertyinfob.GetGetMethod());
    }
 }
 Mypropertyinfo.Main();
 /*
 Produces the following output
 
 Reflection.PropertyInfo
 GetAccessor for Caption returns a System.String
 GetAccessor for MemberType returns a System.Reflection.MemberTypes
 Myproperty.Caption GetGetMethod - System.String get_Caption()
 System.Reflection.MethodInfo.MemberType GetGetMethod - System.Reflection.MemberTypes get_MemberType()
*/

  • ReflectionPermission  when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess.
  • ReflectionPermission  for reflecting methods that are not public. Associated enumeration: ReflectionPermissionFlag.TypeInformation

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:
© 2016 Microsoft