Get public property whose parameters match the specified argument types in CSharp

Description

The following code shows how to get public property whose parameters match the specified argument types.

Example


using System;// w w  w  .j a  v  a2  s.c  o  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.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type