From 7806ccd42f0535f077ab80228e16965d2172dc8a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 10 Apr 2013 11:38:23 -0400 Subject: resharper suggestions in common project --- MediaBrowser.Controller/Localization/Ratings.cs | 32 ++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'MediaBrowser.Controller/Localization') diff --git a/MediaBrowser.Controller/Localization/Ratings.cs b/MediaBrowser.Controller/Localization/Ratings.cs index a8fbdbc80..1220dd8a7 100644 --- a/MediaBrowser.Controller/Localization/Ratings.cs +++ b/MediaBrowser.Controller/Localization/Ratings.cs @@ -35,6 +35,26 @@ namespace MediaBrowser.Controller.Localization /// private static readonly Dictionary ratingsStrings = new Dictionary(); + /// + /// Tries the add. + /// + /// The type of the T key. + /// The type of the T value. + /// The dictionary. + /// The key. + /// The value. + /// true if XXXX, false otherwise + private static bool TryAdd(Dictionary dictionary, TKey key, TValue value) + { + if (dictionary.ContainsKey(key)) + { + return false; + } + + dictionary.Add(key, value); + return true; + } + /// /// Initializes the specified block unrated. /// @@ -48,19 +68,19 @@ namespace MediaBrowser.Controller.Localization var dict = new Dictionary {{"None", -1}}; foreach (var pair in ratingsDef.RatingsDict) { - dict.TryAdd(pair.Key, pair.Value); + TryAdd(dict, pair.Key, pair.Value); } if (configurationManager.Configuration.MetadataCountryCode.ToUpper() != "US") { foreach (var pair in new USRatingsDictionary()) { - dict.TryAdd(pair.Key, pair.Value); + TryAdd(dict, pair.Key, pair.Value); } } //global values of CS - dict.TryAdd("CS", 1000); + TryAdd(dict, "CS", 1000); - dict.TryAdd("", blockUnrated ? 1000 : 0); + TryAdd(dict, "", blockUnrated ? 1000 : 0); //and rating reverse lookup dictionary (non-redundant ones) ratingsStrings.Clear(); @@ -71,11 +91,11 @@ namespace MediaBrowser.Controller.Localization if (pair.Value > lastLevel) { lastLevel = pair.Value; - ratingsStrings.TryAdd(pair.Value, pair.Key); + TryAdd(ratingsStrings, pair.Value, pair.Key); } } - ratingsStrings.TryAdd(999, "CS"); + TryAdd(ratingsStrings, 999, "CS"); return dict; } -- cgit v1.2.3