@@ -8,7 +8,7 @@ namespace Explorer
8
8
{
9
9
public class CachePrimitive : CacheObjectBase
10
10
{
11
- public enum PrimitiveTypes
11
+ public enum Types
12
12
{
13
13
Bool ,
14
14
Double ,
@@ -20,79 +20,49 @@ public enum PrimitiveTypes
20
20
21
21
private string m_valueToString ;
22
22
23
- public PrimitiveTypes PrimitiveType ;
24
-
25
- public MethodInfo ParseMethod
26
- {
27
- get
28
- {
29
- if ( m_parseMethod == null )
30
- {
31
- m_parseMethod = Value . GetType ( ) . GetMethod ( "Parse" , new Type [ ] { typeof ( string ) } ) ;
32
- }
33
- return m_parseMethod ;
34
- }
35
- }
23
+ public Types PrimitiveType ;
36
24
25
+ public MethodInfo ParseMethod => m_parseMethod ?? ( m_parseMethod = Value . GetType ( ) . GetMethod ( "Parse" , new Type [ ] { typeof ( string ) } ) ) ;
37
26
private MethodInfo m_parseMethod ;
38
27
39
28
public override void Init ( )
40
29
{
41
30
if ( Value == null )
42
31
{
43
32
// this must mean it is a string. No other primitive type should be nullable.
44
- PrimitiveType = PrimitiveTypes . String ;
33
+ PrimitiveType = Types . String ;
45
34
return ;
46
35
}
47
36
48
37
m_valueToString = Value . ToString ( ) ;
49
- var type = Value . GetType ( ) ;
50
38
39
+ var type = Value . GetType ( ) ;
51
40
if ( type == typeof ( bool ) )
52
41
{
53
- PrimitiveType = PrimitiveTypes . Bool ;
42
+ PrimitiveType = Types . Bool ;
54
43
}
55
44
else if ( type == typeof ( double ) )
56
45
{
57
- PrimitiveType = PrimitiveTypes . Double ;
46
+ PrimitiveType = Types . Double ;
58
47
}
59
48
else if ( type == typeof ( float ) )
60
49
{
61
- PrimitiveType = PrimitiveTypes . Float ;
50
+ PrimitiveType = Types . Float ;
62
51
}
63
- else if ( IsInteger ( type ) )
52
+ else if ( type == typeof ( char ) )
64
53
{
65
- PrimitiveType = PrimitiveTypes . Int ;
54
+ PrimitiveType = Types . Char ;
66
55
}
67
- else if ( type == typeof ( char ) )
56
+ else if ( typeof ( int ) . IsAssignableFrom ( type ) )
68
57
{
69
- PrimitiveType = PrimitiveTypes . Char ;
58
+ PrimitiveType = Types . Int ;
70
59
}
71
60
else
72
61
{
73
- PrimitiveType = PrimitiveTypes . String ;
62
+ PrimitiveType = Types . String ;
74
63
}
75
64
}
76
65
77
- private static bool IsInteger ( Type type )
78
- {
79
- // For our purposes, all types of int can be treated the same, including IntPtr.
80
- return _integerTypes . Contains ( type ) ;
81
- }
82
-
83
- private static readonly HashSet < Type > _integerTypes = new HashSet < Type >
84
- {
85
- typeof ( int ) ,
86
- typeof ( uint ) ,
87
- typeof ( short ) ,
88
- typeof ( ushort ) ,
89
- typeof ( long ) ,
90
- typeof ( ulong ) ,
91
- typeof ( byte ) ,
92
- typeof ( sbyte ) ,
93
- typeof ( IntPtr )
94
- } ;
95
-
96
66
public override void UpdateValue ( )
97
67
{
98
68
base . UpdateValue ( ) ;
@@ -102,11 +72,10 @@ public override void UpdateValue()
102
72
103
73
public override void DrawValue ( Rect window , float width )
104
74
{
105
- if ( PrimitiveType == PrimitiveTypes . Bool )
75
+ if ( PrimitiveType == Types . Bool )
106
76
{
107
77
var b = ( bool ) Value ;
108
- var color = $ "<color={ ( b ? "lime>" : "red>" ) } ";
109
- var label = $ "{ color } { b } </color>";
78
+ var label = $ "<color={ ( b ? "lime" : "red" ) } >{ b } </color>";
110
79
111
80
if ( CanWrite )
112
81
{
@@ -150,24 +119,23 @@ public override void DrawValue(Rect window, float width)
150
119
}
151
120
}
152
121
153
- public void SetValueFromInput ( string value )
122
+ public void SetValueFromInput ( string valueString )
154
123
{
155
124
if ( MemInfo == null )
156
125
{
157
126
MelonLogger . Log ( "Trying to SetValue but the MemberInfo is null!" ) ;
158
127
return ;
159
128
}
160
129
161
- if ( PrimitiveType == PrimitiveTypes . String )
130
+ if ( PrimitiveType == Types . String )
162
131
{
163
- Value = value ;
132
+ Value = valueString ;
164
133
}
165
134
else
166
135
{
167
136
try
168
137
{
169
- var val = ParseMethod . Invoke ( null , new object [ ] { value } ) ;
170
- Value = val ;
138
+ Value = ParseMethod . Invoke ( null , new object [ ] { valueString } ) ;
171
139
}
172
140
catch ( Exception e )
173
141
{
0 commit comments