File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed
Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -12,25 +12,29 @@ namespace DTD.Sort.Net.Main
1212{
1313 internal class SortFactory < T > where T : IComparable < T >
1414 {
15- public readonly List < ISort < T > > SortLibrary ;
1615
16+ public readonly Dictionary < SortType , ISort < T > > SortLibrary ;
1717 public SortFactory ( )
1818 {
19- SortLibrary = new List < ISort < T > > ( ) ;
19+
20+ SortLibrary = new Dictionary < SortType , ISort < T > > ( ) ;
2021 Assembly algorithmAssembly = Assembly . Load ( "DTD.Sort.Net.Algorithms" ) ;
2122
2223 Type [ ] algorithms = algorithmAssembly . GetTypes ( ) ;
2324 foreach ( Type algorithm in algorithms )
2425 {
2526
2627 var genericType = algorithm . MakeGenericType ( typeof ( T ) ) ;
27- var instance = algorithmAssembly . CreateInstance ( genericType . FullName ) ;
28- SortLibrary . Add ( ( ISort < T > ) instance ) ;
28+ var instance = algorithmAssembly . CreateInstance ( genericType . FullName ! ) ;
29+ var iSortInstance = ( ISort < T > ) instance ;
30+
31+ if ( iSortInstance != null ) SortLibrary [ iSortInstance . Type ] = iSortInstance ;
2932 }
3033
3134 }
3235
33- public ISort < T > GetSort ( SortType type ) => SortLibrary . First ( r => r . Type == type ) ;
36+
37+ public ISort < T > GetSort ( SortType type ) => SortLibrary [ type ] ;
3438
3539 }
3640}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ public class ProductTest
1414
1515
1616 private static IEnumerable < ISort < Product > > TestAssistant =>
17- new SortFactory < Product > ( ) . SortLibrary ;
17+ new SortFactory < Product > ( ) . SortLibrary . Values ;
1818
1919
2020 [ SetUp ]
You can’t perform that action at this time.
0 commit comments