Problem
Unless this exists under a different nomenclature, we don't have class indexers.
Proposed Solution
Provide them
Example Workflow
I have a class I'd like to port from C# to ObjoBasic that basically will open any text file (delimited or fixed width) and return something like a RecordSet so you can iterate through it.
As it is in C#:
tReader = new TextFileReader(somePath);
while (tReader.Read()) {
var x = tReader[0]; // First column value
var y = tReader["AccountNumber"] // Named Column value
}
Alternatives Considered
Without an indexer I would have to either lose array semantics:
var x = tReader.Value(0);
... or lose the ability to enforce read-only on elements of an exposed array representing the row:
var x = tReader.Value[0];
... and of course, that wouldn't work for string key access anyway.
Who Would This Help?
I probably use class indexers in every 100th class I author, but when you need them, they are invaluable for making the client code intuitive and clean.
In .NET it is possible to have multidimensional array syntax from an indexer by creating an indexer on the first item and passing it as an argument to a second indexer. I've only needed it once, and only to reproduce the oddly designed API of another component:
var = myInstance[0][0];
... when:
var = myInstance[0,0]; // this would otherwise be fine.
So I don't personally care if in Objo one can only do a single indexer, at least initially, so long as the Indexer syntax allows multiple args.
Obviously these have to be overloadable so you can, as illustrated above, pass different types as the index (typically integer or string).
Basic syntax would be something like this (a variant of a "computed property"):
Property Me(index As Integer) As String
... followed by a getter and setter.