How to call an indexer property (ex: object this[string param]) using reflection in C#

It's not difficult.
You just call "Item" property.

Sample Code:
==================
Type aType = hasIndexerObject.GetType();
PropertyInfo pi =  aType.PetProperty("Item", typeof(object), new Type[] { typeof(string) });
if (pi != null) {
// call indexter property.
object retValue = pi.GetValue(hasIndexerObject, new object[] {  param });
} else {
// this class didn't have an indexer.
}
==================

--

Ebook Download
View all
Learn
View all