Created
December 30, 2014 21:18
-
-
Save jakesays-old/b242b410b9e024b8c2ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
public class Foo | |
{ | |
public string OtherKey { get; set; } | |
} | |
public class StupidDictionary : IDictionary<string, Foo> | |
{ | |
private readonly Dictionary<string, Foo> _primaryDictionary; | |
private readonly Dictionary<string, Foo> _secondaryDictionary; | |
public StupidDictionary() | |
{ | |
_primaryDictionary = new Dictionary<string, Foo>(); | |
_secondaryDictionary = new Dictionary<string, Foo>(); | |
} | |
public IEnumerator<KeyValuePair<string, Foo>> GetEnumerator() | |
{ | |
return _primaryDictionary.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return ((IEnumerable) _primaryDictionary).GetEnumerator(); | |
} | |
public void Add(KeyValuePair<string, Foo> item) | |
{ | |
((ICollection<KeyValuePair<string, Foo>>) _primaryDictionary).Add(item); | |
} | |
public void Clear() | |
{ | |
_primaryDictionary.Clear(); | |
} | |
public bool Contains(KeyValuePair<string, Foo> item) | |
{ | |
return ((ICollection<KeyValuePair<string, Foo>>) _primaryDictionary).Contains(item); | |
} | |
public void CopyTo(KeyValuePair<string, Foo>[] array, int arrayIndex) | |
{ | |
((ICollection<KeyValuePair<string, Foo>>) _primaryDictionary).CopyTo(array, arrayIndex); | |
} | |
public bool Remove(KeyValuePair<string, Foo> item) | |
{ | |
return ((ICollection<KeyValuePair<string, Foo>>) _primaryDictionary).Remove(item); | |
} | |
public int Count | |
{ | |
get { return _primaryDictionary.Count; } | |
} | |
public bool IsReadOnly | |
{ | |
get { return false; } | |
} | |
public bool ContainsKey(string key) | |
{ | |
return _primaryDictionary.ContainsKey(key); | |
} | |
public bool ContainsSecondaryKey(string key) | |
{ | |
return _secondaryDictionary.ContainsKey(key); | |
} | |
public void Add(string key, Foo value) | |
{ | |
_primaryDictionary.Add(key, value); | |
_secondaryDictionary.Add(value.OtherKey, value); | |
} | |
public bool Remove(string key) | |
{ | |
return _primaryDictionary.Remove(key); | |
} | |
public bool TryGetValue(string key, out Foo value) | |
{ | |
return _primaryDictionary.TryGetValue(key, out value); | |
} | |
public Foo this[string key] | |
{ | |
get { return _primaryDictionary[key]; } | |
set { _primaryDictionary[key] = value; } | |
} | |
public ICollection<string> Keys | |
{ | |
get { return _primaryDictionary.Keys; } | |
} | |
public ICollection<Foo> Values | |
{ | |
get { return _primaryDictionary.Values; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment