C# Type GetProperty(String, Type, Type[])
Description
Type GetProperty(String, Type, Type[])
searches for
the specified public property whose parameters match the specified argument
types.
Syntax
Type.GetProperty(String, Type, Type[])
has the following syntax.
public PropertyInfo GetProperty(
string name,//from www . j a v a 2s.co m
Type returnType,
Type[] types
)
Parameters
Type.GetProperty(String, Type, Type[])
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.
Returns
Type.GetProperty(String, Type, Type[])
method returns An object representing the public property whose parameters match the specified
argument types, if found; otherwise, null.
Example
The following example obtains a Type object corresponding to MyPropertyClass, and the indexed property of this class is retrieved using the arguments passed to the GetProperty method.
using System;// w w w . j a va2 s . co m
using System.Reflection;
public class MyPropertyClass
{
private int [,] myPropertyArray = new int[10,10];
// Declare an indexer.
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.