1
//---------------------------------------------------------------------
2 // <copyright file="BidirectionalDictionary.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System
.Collections
.Generic
;
13 using System
.Globalization
;
15 namespace System
.Data
.Entity
.Design
.PluralizationServices
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.
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))
49 internal virtual bool ExistsInSecond(TSecond
value)
51 if (this.SecondToFirstDictionary
.ContainsKey(value))
58 internal virtual TSecond
GetSecondValue(TFirst
value)
60 if (this.ExistsInFirst(value))
62 return this.FirstToSecondDictionary
[value];
66 return default(TSecond
);
70 internal virtual TFirst
GetFirstValue(TSecond
value)
72 if (this.ExistsInSecond(value))
74 return this.SecondToFirstDictionary
[value];
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()
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());