C# TypeInfo GetProperty(String)

Description

TypeInfo GetProperty(String) Searches for the public property with the specified name.

Syntax

TypeInfo.GetProperty(String) has the following syntax.


public PropertyInfo GetProperty(
  string name
)

Parameters

TypeInfo.GetProperty(String) has the following parameters.

  • name - The string containing the name of the public property to get.

Returns

TypeInfo.GetProperty(String) method returns An object representing the public property with the specified name, if found; otherwise, null.

Example

Searches for the public property with the specified name.


using System;/*www  .ja v  a2  s  .  co  m*/
using System.Reflection;

class MyClass
{
    private int myProperty;
    public int MyProperty
    {
        get
        {
            return myProperty;
        }
        set
        {
            myProperty=value;
        }
    }
}
public class MyTypeClass
{
    public static void Main(string[] args)
    {
        Type myType=typeof(MyClass);       
        PropertyInfo myPropInfo = myType.GetProperty("MyProperty");
        Console.WriteLine("The {0} property exists in MyClass.", myPropInfo.Name);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo