public void WriteDocumentation([NotNull] CommandLineDocumentation documentation) { if (documentation == null) { throw new ArgumentNullException(nameof(documentation)); } foreach (var property in mProperties) { var attribute = property.Item2.GetCustomAttribute <CommandLineAnnotationAttribute>(); if (attribute == null) { attribute = new CommandLineAnnotationAttribute(); } attribute.AddToDocumentation(documentation, property.Item2); } }
public void AddToDocumentation([NotNull] CommandLineDocumentation documentation, [NotNull] PropertyInfo property) { if (documentation == null) { throw new ArgumentNullException(nameof(documentation)); } if (property == null) { throw new ArgumentNullException(nameof(property)); } var attributes = new CommandLineAttribute[] { property.GetCustomAttribute <CommandLinePropertyAttribute>(), property.GetCustomAttribute <CommandLineSwitchAttribute>(), property.GetCustomAttribute <CommandLineValuesAttribute>() }; var attribute = attributes.FirstOrDefault(x => x != null); if (attribute == null) { throw new ArgumentException("The provided property is not bound to a command line token.", nameof(property)); } if (attribute is CommandLineSwitchAttribute) { var switchAttribute = (CommandLineSwitchAttribute)attribute; documentation.AcceptedTokens.Add(new CommandLineSwitchDocumentation(switchAttribute.Name) { AllowMultiple = AcceptsMultiple(property), Description = Description, ShortDescription = ShortDescription, ShortName = switchAttribute.ShortForm }); } if (attribute is CommandLinePropertyAttribute) { var propertyAttribute = (CommandLinePropertyAttribute)attribute; var doc = new CommandLinePropertyDocumentation(propertyAttribute.Name) { AllowMultiple = AcceptsMultiple(property), IsOptional = !IsRequired, Description = Description, ShortDescription = ShortDescription, ShortName = propertyAttribute.ShortForm }; doc.AcceptedValues.AddRange(AcceptedTokens(property.PropertyType, ValueLabel)); documentation.AcceptedTokens.Add(doc); } if (attribute is CommandLineValuesAttribute) { var doc = new CommandLineValueDocumentation { Description = Description, ShortDescription = ShortDescription }; doc.AcceptedValues.AddRange(AcceptedTokens(property.PropertyType, ValueLabel)); documentation.AcceptedTokens.Add(doc); } }