public ObjectBuilder(ParsingTypeInfo typeInfo, IConvertersFactory convertersFactory, IFormatProvider formatProvider) { this.typeInfo = typeInfo ?? throw new ArgumentNullException(nameof(typeInfo)); this.convertersFactory = convertersFactory ?? throw new ArgumentNullException(nameof(convertersFactory)); this.formatProvider = formatProvider ?? throw new ArgumentNullException(nameof(formatProvider)); objectResult = typeInfo.Factory.DynamicInvoke(); maxValuesNumber = typeInfo.Values.Count(); if (typeInfo.Values.Last().IsCollection) { maxValuesNumber += typeInfo.Values.Last().Maximum - 1; } }
public bool Verify(ParsingTypeInfo typeInfo, IList <OptionAttribute> optionAttributes) { if (typeInfo.Values.Select(x => x.Index).HasDuplicates()) { throw new InvalidOperationException("Values must have different indices."); } if (optionAttributes.HasDuplicates()) { throw new InvalidOperationException("Options must have different short names."); } if (optionAttributes.HasDuplicates()) { throw new InvalidOperationException("Options must have different long names."); } if (!(typeInfo is ParsingCommandTypeInfo) && !typeInfo.Options.Any() && !typeInfo.Values.Any()) { throw new InvalidOperationException("Non-command type must have options or values."); } if (typeInfo is ParsingCommandTypeInfo command && types.OfType <ParsingCommandTypeInfo>().SelectMany(x => x.Aliases).HasDuplicates(command.Aliases)) { throw new InvalidOperationException("One of this command's name has been already registered"); }
private TokensParser CreateParser(ParsingTypeInfo typeInfo) => new TokensParser(() => new ObjectBuilder(typeInfo, convertersFactory, formatProvider));