Пример #1
0
 static void WriteEnum<TEnum>( [NotNull] ComboBox box, ConfigKey key ) where TEnum : struct {
     if( box == null ) throw new ArgumentNullException( "box" );
     if( !typeof( TEnum ).IsEnum ) throw new ArgumentException( "Enum type required" );
     try {
         TEnum val = (TEnum)Enum.Parse( typeof( TEnum ), box.SelectedIndex.ToString( CultureInfo.InvariantCulture ), true );
         key.TrySetValue( val );
     } catch( ArgumentException ) {
         Logger.Log( LogType.Error,
                     "ConfigUI.WriteEnum<{0}>: Could not parse value for {1}. Using default ({2}).",
                     typeof( TEnum ).Name, key, key.GetString() );
     }
 }
Пример #2
0
 /// <summary> Resets key value to its default setting. </summary>
 /// <param name="key"> Config key to reset. </param>
 /// <returns> True if value was reset. False if resetting was canceled by an event handler/plugin. </returns>
 public static bool ResetValue(this ConfigKey key)
 {
     return(key.TrySetValue(key.GetDefault()));
 }