Even if there were a separate .get method, it would use the same mechanisms as the indexing/brackets. But here is some help:
Cobra's dictionaries are just the dictionaries straight out of the .NET/Mono libraries. Regardless of which .NET language you use, if you are using a custom class or struct Foo as a key, you often need to override .equals and .getHashCode in Foo. These are used by the dictionary implementation.
The same holds true if you are putting the Foos in Set collections (which come with Cobra, but not .NET).
Without the overrides, I think the dictionary will just use the memory address as the "key" for comparisons and equality tests. That works if your objects are kept unique.
Here's an example:
# disclaimer: untested
class Employee
var _name as String
var _idNumber as String
def init(name as String, idNumber as String)
require
name.trim <> ''
idNumber.trim <> ''
body
_name = name
_idNumber = idNumber
get name from var
get idNumber from var
def toString as String is override
return '[.getType.name]("[.name]", [.idNumber])'
def equals(other as Object) as bool is override
if this is other, return true
if other inherits Employee
return .idNumber == other.idNumber
else
return false
def getHashCode as int is override
return .idNumber.getHashCode
Also, if you want dump the keys in a dictionary:
for key in d.keys, print key
Also, I find it helpful sometimes to take something like "List<of List<of Bar>>" and make a subclass out it like so:
class BarMatrix
inherits List<of List<of Bar>>
pass
One benefit is readability. Now you can say "Dictionary<of Foo, BarMatrix>". Another benefit is that you can add utility methods to BarMatrix as you see fit.
HTH. Let us know how it goes.