C# extend indexer?

Indexers are actually properties, and extension properties do not exist in C#. So this can't be done the way you want.

See this blog post for some background on the subject, and an explanation as to why that feature was considered, but ultimately omitted from C# 3.0.


No, it isn't. Extension methods are just syntactic sugar for static method call, an indexer is a property.

Doing

object o = new object();
o.ExtensionMethod();

is equivalent to

object o = new object();
Extensions.ExtensionMethod(o);

Extension methods don't change the class in any way, they just provide you with a simpler interface to call static methods.


Unfortunately, no. This would effectively be an "extension property", which isn't supported. You must have it as a method, like your current code.

Note that extension properties have been requested on Connect on multiple occasions, but have never been included in the language.