Skip to content

Instantly share code, notes, and snippets.

@pietrom
Created March 28, 2017 14:03
Show Gist options
  • Save pietrom/73fa89837ada34b7f7abb34e842bf4fe to your computer and use it in GitHub Desktop.
Save pietrom/73fa89837ada34b7f7abb34e842bf4fe to your computer and use it in GitHub Desktop.
public static class DictionaryExtension {
public static TOutput GetOrDefault<TOutput, TValue>(this IDictionary<string, TValue> self, string key, TOutput defaultValue)
where TOutput : TValue {
return self.ContainsKey(key) ? (TOutput)self[key] : defaultValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment