Skip to content

Instantly share code, notes, and snippets.

@bitsprint
Created October 7, 2013 19:28
Show Gist options
  • Select an option

  • Save bitsprint/6873519 to your computer and use it in GitHub Desktop.

Select an option

Save bitsprint/6873519 to your computer and use it in GitHub Desktop.
Dictionary Extensions
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