/// <summary> /// Initializes a new instance of the <see cref="CommandLineParser" /> class /// using possible arguments deducted from the specific <see cref="Type" />. /// </summary> /// <param name="argumentSpecification">The <see cref="Type" /> from which the possible command-line arguments should be retrieved.</param> /// <param name="supportsResponseFile">A <see cref="bool" /> value indicating whether or not a response file is able to be used. </param> /// <exception cref="ArgumentNullException"><paramref name="argumentSpecification" /> is a null reference.</exception> public CommandLineParser(Type argumentSpecification, bool supportsResponseFile) { if (argumentSpecification == null) { throw new ArgumentNullException("argumentSpecification"); } _argumentCollection = new CommandLineArgumentCollection(); foreach (PropertyInfo propertyInfo in argumentSpecification.GetProperties(BindingFlags.Instance | BindingFlags.Public)) { if (propertyInfo.CanWrite || typeof(ICollection).IsAssignableFrom(propertyInfo.PropertyType)) { CommandLineArgumentAttribute attribute = GetCommandLineAttribute(propertyInfo); if (attribute is DefaultCommandLineArgumentAttribute) { Debug.Assert(_defaultArgument == null); _defaultArgument = new CommandLineArgument(attribute, propertyInfo); } else if (attribute != null) { _argumentCollection.Add(new CommandLineArgument(attribute, propertyInfo)); } } } _argumentSpecification = argumentSpecification; _supportsResponseFile = supportsResponseFile; }
private static CommandLineArgumentTypes GetArgumentType(CommandLineArgumentAttribute attribute, PropertyInfo propertyInfo) { if (attribute != null) { return(attribute.Type); } else if (IsCollectionType(propertyInfo.PropertyType)) { return(CommandLineArgumentTypes.MultipleUnique); } else { return(CommandLineArgumentTypes.AtMostOnce); } }
/// <summary> /// Initializes a new instance of the <see cref="CommandLineArgument"/> class. /// </summary> /// <param name="attribute">The attribute.</param> /// <param name="propertyInfo">The property information.</param> public CommandLineArgument(CommandLineArgumentAttribute attribute, PropertyInfo propertyInfo) { _attribute = attribute; _propertyInfo = propertyInfo; _seenValue = false; _elementType = GetElementType(propertyInfo); _argumentType = GetArgumentType(attribute, propertyInfo); if (IsCollection || IsArray) { _collectionValues = new ArrayList(); } else if (IsNameValueCollection) { _valuePairs = new NameValueCollection(); } Debug.Assert(LongName != null && LongName.Length > 0); Debug.Assert((!IsCollection && !IsArray && !IsNameValueCollection) || AllowMultiple, "Collection and array arguments must have allow multiple"); Debug.Assert(!Unique || (IsCollection || IsArray || IsNameValueCollection), "Unique only applicable to collection arguments"); }
public CommandLineArgument(CommandLineArgumentAttribute attribute, PropertyInfo propertyInfo) { _attribute = attribute; _propertyInfo = propertyInfo; _seenValue = false; _elementType = GetElementType(propertyInfo); _argumentType = GetArgumentType(attribute, propertyInfo); if (IsCollection || IsArray) { _collectionValues = new ArrayList(); } else if (IsNameValueCollection) { _valuePairs = new NameValueCollection(); } Debug.Assert(LongName != null && LongName.Length > 0); Debug.Assert((!IsCollection && !IsArray && !IsNameValueCollection) || AllowMultiple, "Collection and array arguments must have allow multiple"); Debug.Assert(!Unique || (IsCollection || IsArray || IsNameValueCollection), "Unique only applicable to collection arguments"); }
private static CommandLineArgumentTypes GetArgumentType(CommandLineArgumentAttribute attribute, PropertyInfo propertyInfo) { if (attribute != null) { return attribute.Type; } else if (IsCollectionType(propertyInfo.PropertyType)) { return CommandLineArgumentTypes.MultipleUnique; } else { return CommandLineArgumentTypes.AtMostOnce; } }