C# TypeInfo GetProperty(String, Type, Type[], ParameterModifier[])

Description

TypeInfo GetProperty(String, Type, Type[], ParameterModifier[]) Searches for the specified public property whose parameters match the specified argument types and modifiers.

Syntax

TypeInfo.GetProperty(String, Type, Type[], ParameterModifier[]) has the following syntax.


public PropertyInfo GetProperty(
  string name,//from w  w  w  . j a  v a2  s . c  om
  Type returnType,
  Type[] types,
  ParameterModifier[] modifiers
)

Parameters

TypeInfo.GetProperty(String, Type, Type[], ParameterModifier[]) has the following parameters.

  • name - The string containing the name of the public property to get.
  • returnType - The return type of the property.
  • types - An array of Type objects representing the number, order, and type of the parameters for the indexed property to get.
  • types - -or-
  • types - An empty array of the type Type (that is, Type[] types = new Type[0]) to get a property that is not indexed.
  • modifiers - An array of ParameterModifier objects representing the attributes associated with the corresponding element in the types array. The default binder does not process this parameter.

Returns

TypeInfo.GetProperty(String, Type, Type[], ParameterModifier[]) method returns An object representing the public property that matches the specified requirements, if found; otherwise, null.

Example


using System;/*  w  w  w.ja v a 2s.  c  o  m*/
using System.Reflection;
public class MyPropertyClass
{
    private int [,] myPropertyArray = new int[10,10]; 
    public int this [int i,int j]
    {
        get 
        {
            return myPropertyArray[i,j];
        }
        set 
        {
            myPropertyArray[i,j] = value;
        }
    }
}
public class MyTypeClass
{
    public static void Main()
    {
       Type myType=typeof(MyPropertyClass);
       Type[] myTypeArray = new Type[2];
       myTypeArray.SetValue(typeof(int),0);
       myTypeArray.SetValue(typeof(int),1);
       PropertyInfo myPropertyInfo = myType.GetProperty("Item",typeof(int),myTypeArray,null);
       Console.WriteLine(myType.FullName + "." + myPropertyInfo.Name + " has a property type of " + myPropertyInfo.PropertyType);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Reflection »




EventInfo
FieldInfo
MemberInfo
MethodInfo
ParameterInfo
TypeInfo