@@ -8,47 +8,71 @@ public static class UnitsCollector
8
8
{
9
9
public static List < UnitInfo > GetBuiltinParametersInfo ( )
10
10
{
11
- var parameters = Enum . GetValues ( typeof ( BuiltInParameter ) ) ;
11
+ #if NETCOREAPP
12
+ var parameters = Enum . GetValues < BuiltInParameter > ( ) ;
13
+ var parameterNames = Enum . GetNames < BuiltInParameter > ( ) ;
14
+ #else
15
+ var parameters = Enum . GetValues ( typeof ( BuiltInParameter ) ) . Cast < BuiltInParameter > ( ) . ToArray ( ) ;
16
+ var parameterNames = Enum . GetNames ( typeof ( BuiltInParameter ) ) ;
17
+ #endif
12
18
var result = new List < UnitInfo > ( parameters . Length ) ;
13
- foreach ( BuiltInParameter parameter in parameters )
19
+ for ( var i = 0 ; i < parameters . Length ; i ++ )
20
+ {
21
+ var parameter = parameters [ i ] ;
22
+ string label ;
14
23
try
15
24
{
16
- result . Add ( new UnitInfo
17
- {
18
- Unit = parameter . ToString ( ) ,
19
- Label = parameter . ToLabel ( ) ,
20
- Value = parameter
21
- } ) ;
25
+ label = parameter . ToLabel ( ) ;
22
26
}
23
27
catch
24
28
{
25
- // ignored
26
29
// Some parameters don't have a label
30
+ label = string . Empty ;
27
31
}
28
32
33
+ result . Add ( new UnitInfo
34
+ {
35
+ Unit = parameterNames [ i ] ,
36
+ Label = label ,
37
+ Value = parameter
38
+ } ) ;
39
+ }
40
+
29
41
return result ;
30
42
}
31
43
32
44
public static List < UnitInfo > GetBuiltinCategoriesInfo ( )
33
45
{
34
- var categories = Enum . GetValues ( typeof ( BuiltInCategory ) ) ;
46
+ #if NETCOREAPP
47
+ var categories = Enum . GetValues < BuiltInCategory > ( ) ;
48
+ var categoryNames = Enum . GetNames < BuiltInCategory > ( ) ;
49
+ #else
50
+ var categories = Enum . GetValues ( typeof ( BuiltInCategory ) ) . Cast < BuiltInCategory > ( ) . ToArray ( ) ;
51
+ var categoryNames = Enum . GetNames ( typeof ( BuiltInCategory ) ) ;
52
+ #endif
35
53
var result = new List < UnitInfo > ( categories . Length ) ;
36
- foreach ( BuiltInCategory category in categories )
54
+ for ( var i = 0 ; i < categories . Length ; i ++ )
55
+ {
56
+ var category = categories [ i ] ;
57
+ string label ;
37
58
try
38
59
{
39
- result . Add ( new UnitInfo
40
- {
41
- Unit = category . ToString ( ) ,
42
- Label = category . ToLabel ( ) ,
43
- Value = category
44
- } ) ;
60
+ label = category . ToLabel ( ) ;
45
61
}
46
62
catch
47
63
{
48
- // ignored
49
64
// Some categories don't have a label
65
+ label = string . Empty ;
50
66
}
51
67
68
+ result . Add ( new UnitInfo
69
+ {
70
+ Unit = categoryNames [ i ] ,
71
+ Label = label ,
72
+ Value = category
73
+ } ) ;
74
+ }
75
+
52
76
return result ;
53
77
}
54
78
0 commit comments