I need the following (using string as the type here for brevity):
MyDictionary : IDictionary<string, List<string>>
{
private readonly Dictionary<string, List<string>> _collection;
...
// The collection cannot contain the key
public void Add(string key, List<string> value)
{
_collection.Add(key, new List<string>(value.RemoveAll(p => p == key));
}
}
So in use you might have:
string myName = "Superstringcheese";
List<string> myFriends = new List<string> {"John", "Jane", "Jerry"};
string yourName = "Someone";
List<string> yourFriends = new List<string> {"John", "Bill", "Ted"};
var myDic = new MyDictionary();
// It's okay that each of us (each key) has some friends that are the same. It's not okay for me to have myself as a friend. The add method would check if the key is contained by the value collection and remove it if necessary.
myDic.Add(myName, myFriends);
myDic.Add(yourName, yourFriends);
Before I go reinventing any wheels, is there a native collection type that does this, or does anyone know of a popular implementation?
Well, I can help with this bit:
No.