Get public property whose parameters match the specified argument types and modifiers in CSharp
Description
The following code shows how to get public property whose parameters match the specified argument types and modifiers.
Example
using System;/*from w w w.j ava 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.