// ------------------------------------------ // ACCESSORS // ------------------------------------------ #region Accessors // Arguments -------------------------------- /// <summary> /// Retrieves the arguments from the specified argument string values. /// </summary> /// <param name="arguments">The argument string values to consider.</param> /// <param name="optionSpecificationSet">The option specification set to consider.</param> /// <param name="allowMissingItems">Indicates whether the items can be missing.</param> /// <param name="log">The log to consider.</param> /// <returns>Returns the log of argument building.</returns> public static IOptionSet UpdateOptions( this string[] arguments, IOptionSpecSet optionSpecificationSet, bool allowMissingItems = false, IBdoLog log = null) { IOptionSet optionSet = new OptionSet(); int index = 0; if (arguments != null) { while (index < arguments.Length) { string currentArgumentString = arguments[index]; if (currentArgumentString != null) { IScalarElement argument = null; OptionSpec argumentSpecification = null; int aliasIndex = -2; if (optionSpecificationSet != null) { argumentSpecification = optionSpecificationSet.Items .Find(p => p.IsArgumentMarching(currentArgumentString, out aliasIndex)) as OptionSpec; } if (optionSpecificationSet == null || (argumentSpecification == null && allowMissingItems)) { argument = ElementFactory.CreateScalar(currentArgumentString, DataValueTypes.Text); argument.WithItems(arguments.GetStringAtIndex(index)); optionSet.Add(argument); } else if (argumentSpecification != null && optionSpecificationSet != null) { if (argumentSpecification.ValueType == DataValueTypes.Any) { argumentSpecification.ValueType = DataValueTypes.Text; } argument = ElementFactory.CreateScalar(argumentSpecification.Name, null, argumentSpecification.ValueType, argumentSpecification); argument.Specification = argumentSpecification; if (argumentSpecification.ItemRequirementLevel.IsPossible()) { if (argumentSpecification.Name.Contains(StringHelper.__PatternEmptyValue)) { argument.Name = argumentSpecification.Name.ToSubstring(0, argumentSpecification.Name.Length - StringHelper.__PatternEmptyValue.Length - 2); int valueIndex = -1; if (aliasIndex == -1) { valueIndex = argumentSpecification.Name.IndexOf(StringHelper.__PatternEmptyValue); } else if (aliasIndex > -1) { valueIndex = argumentSpecification.Aliases[aliasIndex].IndexOf(StringHelper.__PatternEmptyValue); } argument.WithItems(valueIndex < 0 ? string.Empty : currentArgumentString.ToSubstring(valueIndex)); } else { index++; if (index < arguments.Length) { argument.WithItems(arguments.GetStringAtIndex(index)); } } } optionSet.Add(argument); } } index++; } } optionSet.Check(optionSpecificationSet).AddEventsTo(log); return(optionSet); }