2222namespace Common . Util
2323{
2424 /// <summary>
25- /// Provides a default implementation of ExtendedDictionary that can be used with any key-value pair types
25+ /// Provides a generic implementation of ExtendedDictionary with specific dictionary type
2626 /// </summary>
2727 [ PandasNonExpandable ]
28- public class BaseExtendedDictionary < TKey , TValue > : ExtendedDictionary < TKey , TValue > , IDictionary < TKey , TValue >
28+ public class BaseExtendedDictionary < TKey , TValue , TDictionary > : ExtendedDictionary < TKey , TValue > , IDictionary < TKey , TValue >
29+ where TDictionary : IDictionary < TKey , TValue > , new ( )
2930 {
3031 /// <summary>
3132 /// The dictionary instance
3233 /// </summary>
33- protected IDictionary < TKey , TValue > Dictionary { get ; }
34+ protected TDictionary Dictionary { get ; }
3435
3536 /// <summary>
3637 /// Initializes a new instance of the BaseExtendedDictionary class that is empty
3738 /// </summary>
38- public BaseExtendedDictionary ( ) : this ( new Dictionary < TKey , TValue > ( ) )
39+ public BaseExtendedDictionary ( )
3940 {
41+ Dictionary = new TDictionary ( ) ;
4042 }
4143
4244 /// <summary>
4345 /// Initializes a new instance of the BaseExtendedDictionary class that contains elements copied from the specified dictionary
4446 /// </summary>
4547 /// <param name="dictionary">The dictionary whose elements are copied to the new dictionary</param>
46- public BaseExtendedDictionary ( IDictionary < TKey , TValue > dictionary )
48+ public BaseExtendedDictionary ( TDictionary dictionary )
4749 {
4850 Dictionary = dictionary ;
4951 }
@@ -55,7 +57,7 @@ public BaseExtendedDictionary(IDictionary<TKey, TValue> dictionary)
5557 /// <param name="data">The data source for this dictionary</param>
5658 /// <param name="keySelector">Delegate used to select a key from the value</param>
5759 public BaseExtendedDictionary ( IEnumerable < TValue > data , Func < TValue , TKey > keySelector )
58- : this ( new Dictionary < TKey , TValue > ( ) )
60+ : this ( )
5961 {
6062 foreach ( var datum in data )
6163 {
@@ -221,32 +223,24 @@ IEnumerator IEnumerable.GetEnumerator()
221223 }
222224
223225 /// <summary>
224- /// Provides a generic implementation of ExtendedDictionary with specific dictionary type
226+ /// Provides a default implementation of ExtendedDictionary using Dictionary{TKey, TValue}
225227 /// </summary>
226228 [ PandasNonExpandable ]
227- public class BaseExtendedDictionary < TKey , TValue , TDictionary > : BaseExtendedDictionary < TKey , TValue >
228- where TDictionary : IDictionary < TKey , TValue > , new ( )
229+ public class BaseExtendedDictionary < TKey , TValue > : BaseExtendedDictionary < TKey , TValue , Dictionary < TKey , TValue > >
229230 {
230- /// <summary>
231- /// Gets the typed dictionary instance
232- /// </summary>
233- protected TDictionary TypedDictionary { get ; }
234-
235231 /// <summary>
236232 /// Initializes a new instance of the BaseExtendedDictionary class that is empty
237233 /// </summary>
238- public BaseExtendedDictionary ( ) : base ( new TDictionary ( ) )
234+ public BaseExtendedDictionary ( ) : base ( )
239235 {
240- TypedDictionary = ( TDictionary ) Dictionary ;
241236 }
242237
243238 /// <summary>
244239 /// Initializes a new instance of the BaseExtendedDictionary class that contains elements copied from the specified dictionary
245240 /// </summary>
246241 /// <param name="dictionary">The dictionary whose elements are copied to the new dictionary</param>
247- public BaseExtendedDictionary ( TDictionary dictionary ) : base ( dictionary )
242+ public BaseExtendedDictionary ( IDictionary < TKey , TValue > dictionary ) : base ( new Dictionary < TKey , TValue > ( dictionary ) )
248243 {
249- TypedDictionary = dictionary ;
250244 }
251245
252246 /// <summary>
@@ -255,14 +249,8 @@ public BaseExtendedDictionary(TDictionary dictionary) : base(dictionary)
255249 /// </summary>
256250 /// <param name="data">The data source for this dictionary</param>
257251 /// <param name="keySelector">Delegate used to select a key from the value</param>
258- public BaseExtendedDictionary ( IEnumerable < TValue > data , Func < TValue , TKey > keySelector )
259- : base ( new TDictionary ( ) )
252+ public BaseExtendedDictionary ( IEnumerable < TValue > data , Func < TValue , TKey > keySelector ) : base ( data , keySelector )
260253 {
261- TypedDictionary = ( TDictionary ) Dictionary ;
262- foreach ( var datum in data )
263- {
264- TypedDictionary [ keySelector ( datum ) ] = datum ;
265- }
266254 }
267255 }
268256}
0 commit comments