Indexer reflection
In this chapter you will learn:
Reflection on Indexer
The following code
uses Type
and PropertyInfo
to manipulate the indexer.
using System;// ja v a 2 s . c o m
using System.Reflection;
public class MyClass
{
private int [,] myValue = new int[10,10];
public int this [int i,int j]
{
get
{
return myValue[i,j];
}
set
{
myValue[i,j] = value;
}
}
}
public class MyTypeClass
{
public static void Main()
{
try
{
Type myType=typeof(MyClass);
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);
Console.WriteLine(myPropertyInfo.Name);
Console.WriteLine(myPropertyInfo.PropertyType);
}catch(Exception ex){
Console.WriteLine("An exception occurred " + ex.Message);
}
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Reflection