@@ -43,6 +43,11 @@ public interface IPluginOption
43
43
/// based on the settings of other options or any other desired criteria
44
44
/// </summary>
45
45
public Func < bool > If { get ; set ; }
46
+
47
+ /// <summary>
48
+ /// Set an option from a string value
49
+ /// </summary>
50
+ public void SetFromString ( string value ) ;
46
51
}
47
52
48
53
/// <summary>
@@ -112,6 +117,11 @@ public T Value {
112
117
}
113
118
}
114
119
120
+ /// <summary>
121
+ /// Set an option from a string value
122
+ /// </summary>
123
+ public abstract void SetFromString ( string value ) ;
124
+
115
125
/// <summary>
116
126
/// This can be set to a predicate that determines whether the option is enabled in the GUI
117
127
/// By default, enable all options unless overridden
@@ -154,6 +164,8 @@ protected sealed override void InternalValidate(string text) {
154
164
if ( Required && string . IsNullOrWhiteSpace ( text ) )
155
165
throw new ArgumentException ( "Text cannot be empty" ) ;
156
166
}
167
+
168
+ public override void SetFromString ( string value ) => Value = value ;
157
169
}
158
170
159
171
/// <summary>
@@ -220,6 +232,8 @@ protected sealed override void InternalValidate(string path) {
220
232
public Dictionary < string , string > AllowedExtensions = new Dictionary < string , string > {
221
233
[ "*" ] = "All files"
222
234
} ;
235
+
236
+ public override void SetFromString ( string value ) => Value = value ;
223
237
}
224
238
225
239
/// <summary>
@@ -228,6 +242,8 @@ protected sealed override void InternalValidate(string path) {
228
242
public class PluginOptionBoolean : PluginOption < bool >
229
243
{
230
244
protected sealed override void InternalValidate ( bool value ) { }
245
+
246
+ public override void SetFromString ( string value ) => Value = bool . Parse ( value ) ;
231
247
}
232
248
233
249
/// <summary>
@@ -248,6 +264,10 @@ public class PluginOptionNumber<T> : PluginOption<T>, IPluginOptionNumber where
248
264
object IPluginOptionNumber . Value { get => Value ; set => Value = ( T ) value ; }
249
265
250
266
protected sealed override void InternalValidate ( T value ) { }
267
+
268
+ public override void SetFromString ( string value ) {
269
+ Value = ( T ) Convert . ChangeType ( Convert . ToInt64 ( value , Style == PluginOptionNumberStyle . Hex ? 16 : 10 ) , typeof ( T ) ) ;
270
+ }
251
271
}
252
272
253
273
/// <summary>
@@ -273,5 +293,12 @@ protected sealed override void InternalValidate(T value) {
273
293
if ( ! Choices ? . Keys . Contains ( value ) ?? false )
274
294
throw new ArgumentException ( "Specified choice is not one of the available choices" ) ;
275
295
}
296
+
297
+ public override void SetFromString ( string value ) {
298
+ if ( typeof ( T ) . IsEnum )
299
+ Value = ( T ) Enum . Parse ( typeof ( T ) , value ) ;
300
+ else
301
+ Value = ( T ) Convert . ChangeType ( value , typeof ( T ) ) ;
302
+ }
276
303
}
277
304
}
0 commit comments