Wiki

Changeset 2318

Show
Ignore:
Timestamp:
03/14/10 08:28:09 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Added IDictionary<of TKey, TValue>.get(key as TKey, default as TValue) as TValue

Location:
cobra/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r2315 r2318  
    6464================================================================================ 
    6565 
    66 * Added extension methods to List<of T>. @@ expand on this 
     66* Added extension methods to IList<of T>. @@ expand on this 
     67 
     68* Added extension methods to IDictionary<of TKey, TValue>. @@ expand on this 
    6769 
    6870* Moved useful Utils methods to extension methods.  ticket:111 
  • cobra/trunk/Source/Boxes.cobra

    r2316 r2318  
    15571557        return true 
    15581558 
     1559    get isUninitializedForLocalVars as bool is override 
     1560        return false  # TODO: could use a more sophisticated implementation 
     1561 
    15591562    get name as String is override 
    15601563        return _name 
  • cobra/trunk/Source/Cobra.Lang/ExtendDictionary.cobra

    r2246 r2318  
    1818                return newDict 
    1919 
     20        def get(key as TKey, default as TValue) as TValue 
     21            """ 
     22            Returns the value for the given key, or returns the default if the key is not found. 
     23            """ 
     24            ensure not .containsKey(key) implies result == default 
     25            value as TValue 
     26            if .tryGetValue(key, out value), return value 
     27            else, return default 
     28 
     29 
    2030    class TestIDictionaryExtensions 
    2131 
     
    3242            assert b.count == 2 
    3343            assert b['x'] == 1 and b['y'] == 2 
     44 
     45            d = {'a': 1, 'b': 2} 
     46            assert d.get('a', 0) == 1 
     47            assert d.get('c', 1) == 1 
  • cobra/trunk/Tests/240-generics/100-use-generics-collections/110-use-dictionary.cobra

    r1177 r2318  
    1313        for value1 as String in t.values 
    1414            assert value1.length 
     15        assert t.get('a', 'c') == 'b' 
     16        assert t.get('x', 'c') == 'c' 
    1517             
    1618        u as Dictionary<of String, int> = Dictionary<of String, int>()