public OptionDetails ToOptionDetails() { OptionDetails od = new OptionDetails(); od.Font = Font; od.Notification = Notifications; od.Theme = Theme; od.UserNickname = ChamberOfSecrets.Instance.LoggedUser.UserName; return(od); }
public void ToOption(OptionDetails details) { Theme = details.Theme; Font = details.Font; Notifications = details.Notification; }
public ParserResult <T> Parse <T>(IList <string> args) where T : new() { var optionsInstance = new T(); var optionDetailsList = OptionDetails.Build(typeof(T)); var errors = new List <IParserError>(); Validate(errors, optionDetailsList); if (!errors.Any()) { ApplyDefaultValues(errors, optionsInstance, optionDetailsList); } if (!errors.Any()) { var position = 0; IOptionDetails currentOption = null; foreach (var arg in args) { if (string.IsNullOrEmpty(arg)) { continue; } if (currentOption != null) { try { currentOption.SetValue(optionsInstance, arg); } catch (Exception) { errors.Add(new InvalidOptionValueError(currentOption, arg)); } currentOption = null; continue; } if (IsLongOption(Configuration, arg)) { var optionName = arg.Before("="); currentOption = FindOption(optionDetailsList, optionName); if (currentOption == null) { errors.Add(new UnknownOptionError(arg)); } } if (IsShortOption(Configuration, arg)) { var optionName = ExtractOptionName(Configuration, arg); currentOption = FindOption(optionDetailsList, optionName); if (currentOption == null) { errors.Add(new UnknownOptionError(optionName)); } continue; } // Find Parameter var parameter = FindParameter(optionDetailsList, position); if (parameter == null) { errors.Add(new UnknownParameterError(position)); continue; } try { parameter.SetValue(optionsInstance, arg); } catch (Exception ex) { Debug.WriteLine(ex.Message); errors.Add(new InvalidOptionValueError(parameter, arg)); } ++position; } } var result = new ParserResult <T>( optionsInstance, Configuration, optionDetailsList, errors ); return(result); }