As an example, I'll use SqlDataReader and DataRow classes: they both define the following indexer:
public object this[int columnIndex] { get; set; }
What is the lowest common denominator type to use as method's parameter type, so that both (and any other class implementing same indexer) can be passed and used in the same fashion, e.g.:
void DoSomething(??? indexedObject)
{
string foo = indexedObject[0].ToString();
// let's ignore the presence of ToString()
// for the purpose of this question
}
Is it object
? What if the indexed object does not derive from object
(I think that's possible, even though very unlikely).
If it matters, I am targeting .NET 3.5.
Edit: I am looking for some contract enforcement that causes callers to pass objects that implement said indexer.