@@ -118,6 +118,23 @@ public class ModConfigurationKey<T> : ModConfigurationKey
118118 /// </summary>
119119 public DefiningConfigKey < T > Key { get ; }
120120
121+ /// <summary>
122+ /// Gets or sets the value of this configuration key.
123+ /// </summary>
124+ /// <remarks>
125+ /// When getting, attempts to retrieve the current value assigned to this key, or <c>default(T)</c> if none is set.<br/>
126+ /// When setting, assigns the provided value to this key and notifies any <see cref="ModConfigurationKey.OnChanged">OnChanged</see> subscribers.
127+ /// </remarks>
128+ public T ? Value
129+ {
130+ get => Key . GetValue ( ) ;
131+
132+ // In RML this bypasses the validation check, but ML doesn't let anything set an invalid value.
133+ // A debate could be had as to whether to use the version that throws or not,
134+ // but I'm using the one that throws to not let a mod continue with the old value if the new one is invalid.
135+ set => Key . SetValue ( value ! ) ;
136+ }
137+
121138 internal override IDefiningConfigKey UntypedKey => Key ;
122139
123140 /// <inheritdoc/>
@@ -195,24 +212,5 @@ private void OnKeyChanged(object sender, ConfigKeyChangedEventArgs<T> configKeyC
195212 FireOnChanged ( configKeyChangedEventArgs . NewValue ) ;
196213 ModConfiguration . FireConfigurationChangedEvent ( this , configKeyChangedEventArgs . Label ) ;
197214 }
198-
199- /// <summary>
200- /// Gets or sets the value of this configuration key.
201- /// <para>
202- /// When getting, attempts to retrieve the current value assigned to this key, or <c>default(T)</c> if none is set.
203- /// When setting, assigns the provided value to this key and notifies any <see cref="OnChanged"/> subscribers.
204- /// </para>
205- /// </summary>
206- public T ? Value
207- {
208- get
209- {
210- return ( T ? ) ModConfiguration . GetValue ( this ) ;
211- }
212- set
213- {
214- ModConfiguration . Set ( this , value ) ;
215- }
216- }
217215 }
218216}
0 commit comments