Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity.Design / System / Data / Entity / Design / PluralizationService / BidirectionalDictionary.cs
blobf40b624560d6d50dfeaf403d2cb85bf9d3563d56
1 //---------------------------------------------------------------------
2 // <copyright file="BidirectionalDictionary.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9 using System;
10 using System.Collections.Generic;
11 using System.Linq;
12 using System.Text;
13 using System.Globalization;
15 namespace System.Data.Entity.Design.PluralizationServices
17 /// <summary>
18 /// This class provide service for both the singularization and pluralization, it takes the word pairs
19 /// in the ctor following the rules that the first one is singular and the second one is plural.
20 /// </summary>
21 internal class BidirectionalDictionary<TFirst, TSecond>
23 internal Dictionary<TFirst, TSecond> FirstToSecondDictionary { get; set; }
24 internal Dictionary<TSecond, TFirst> SecondToFirstDictionary { get; set; }
26 internal BidirectionalDictionary()
28 this.FirstToSecondDictionary = new Dictionary<TFirst, TSecond>();
29 this.SecondToFirstDictionary = new Dictionary<TSecond, TFirst>();
32 internal BidirectionalDictionary(Dictionary<TFirst,TSecond> firstToSecondDictionary) : this()
34 foreach (var key in firstToSecondDictionary.Keys)
36 this.AddValue(key, firstToSecondDictionary[key]);
40 internal virtual bool ExistsInFirst(TFirst value)
42 if (this.FirstToSecondDictionary.ContainsKey(value))
44 return true;
46 return false;
49 internal virtual bool ExistsInSecond(TSecond value)
51 if (this.SecondToFirstDictionary.ContainsKey(value))
53 return true;
55 return false;
58 internal virtual TSecond GetSecondValue(TFirst value)
60 if (this.ExistsInFirst(value))
62 return this.FirstToSecondDictionary[value];
64 else
66 return default(TSecond);
70 internal virtual TFirst GetFirstValue(TSecond value)
72 if (this.ExistsInSecond(value))
74 return this.SecondToFirstDictionary[value];
76 else
78 return default(TFirst);
82 internal void AddValue(TFirst firstValue, TSecond secondValue)
84 this.FirstToSecondDictionary.Add(firstValue, secondValue);
86 if (!this.SecondToFirstDictionary.ContainsKey(secondValue))
88 this.SecondToFirstDictionary.Add(secondValue, firstValue);
93 internal class StringBidirectionalDictionary : BidirectionalDictionary<string, string>
96 internal StringBidirectionalDictionary()
97 : base()
98 { }
99 internal StringBidirectionalDictionary(Dictionary<string, string> firstToSecondDictionary)
100 : base(firstToSecondDictionary)
103 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
104 internal override bool ExistsInFirst(string value)
106 return base.ExistsInFirst(value.ToLowerInvariant());
109 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
110 internal override bool ExistsInSecond(string value)
112 return base.ExistsInSecond(value.ToLowerInvariant());
115 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
116 internal override string GetFirstValue(string value)
118 return base.GetFirstValue(value.ToLowerInvariant());
121 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
122 internal override string GetSecondValue(string value)
124 return base.GetSecondValue(value.ToLowerInvariant());