Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jeremydmiller/8786b6d0caa2b58a00a7f530710bcbc0 to your computer and use it in GitHub Desktop.
Save jeremydmiller/8786b6d0caa2b58a00a7f530710bcbc0 to your computer and use it in GitHub Desktop.
/// <summary>
/// This is a big THANK YOU to the BCL for not hooking a brotha' up
/// This add will tell WHAT KEY you added twice.
/// </summary>
public static void SmartAdd<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key, TValue value)
{
try
{
dictionary.Add(key, value);
}
catch (ArgumentException e)
{
throw new ArgumentException("The key '{0}' already exists.".ToFormat(key), e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment