ViIvanov

IDictionary<,>::GetValue

Oct 8th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.53 KB | None | 0 0
  1. public static class DictionaryExtensions
  2. {
  3.   [DebuggerHidden]
  4.   public static TValue GetValue<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key) {
  5.     if(source == null) {
  6.       throw new ArgumentNullException("source");
  7.     }//if
  8.  
  9.     TValue value;
  10.     if(!source.TryGetValue(key, out value)) {
  11.       const string Format = "Key \"{0}\" does not found in a dictionary.";
  12.       var message = String.Format(Format, key);
  13.       throw new KeyNotFoundException(message);
  14.     }//if
  15.  
  16.     return value;
  17.   }
  18.  
  19.   // …
  20. }
Advertisement
Add Comment
Please, Sign In to add comment