C# TypeInfo GetProperty(String, Type[]) Array
Description
TypeInfo GetProperty(String, Type[])
Searches for
the specified public property whose parameters match the specified argument
types.
Syntax
TypeInfo.GetProperty(String, Type[])
has the following syntax.
public PropertyInfo GetProperty(
string name,
Type[] types
)
Parameters
TypeInfo.GetProperty(String, Type[])
has the following parameters.
name
- The string containing the name of the public property to get.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
TypeInfo.GetProperty(String, Type[])
method returns An object representing the public property whose parameters match the specified
argument types, if found; otherwise, null.
Example
using System;// w w w .j a va2 s. co m
using System.Reflection;
class MyClass1
{
private int [,] myArray = {{1,2},{3,4}};
public int this [int i,int j]
{
get
{
return myArray[i,j];
}
set
{
myArray[i,j] = value;
}
}
}
public class MyTypeClass
{
public static void Main(string[] args)
{
Type myType=typeof(MyClass1);
Type[] myTypeArr = new Type[2];
myTypeArr.SetValue(typeof(int),0);
myTypeArr.SetValue(typeof(int),1);
PropertyInfo myPropInfo = myType.GetProperty("Item", myTypeArr);
Console.WriteLine("The {0} property exists in MyClass1.", myPropInfo.ToString());
}
}
The code above generates the following result.