public CommandGroupArgumentType(Type type) : base(type) { if (!type.GetTypeInfo().IsGenericType) { throw new ArgumentOutOfRangeException(nameof(type)); } var typeParams = type.GetTypeInfo().GetGenericArguments(); if (typeParams.Length != 1) { throw new ArgumentOutOfRangeException(nameof(type)); } if (!type.GetGenericTypeDefinition().IsEffectivelySameAs(typeof(CommandGroup <>))) { throw new ArgumentOutOfRangeException(nameof(type)); } _commandTypeType = typeParams[0]; if (!_commandTypeType.GetTypeInfo().IsEnum) { throw new ArgumentOutOfRangeException(nameof(type)); } if (!ArgumentType.TryGetType(_commandTypeType, out IArgumentType commandArgType)) { throw new ArgumentOutOfRangeException(nameof(type)); } _commandArgType = (IEnumArgumentType)commandArgType; }
/// <summary> /// Defines all values in the given type. /// </summary> /// <param name="type">Type to inspect.</param> protected void AddValuesFromType(IEnumArgumentType type) { foreach (var value in type.GetValues()) { AddValue(value); } }
private IEnumerable <ColoredMultistring> GetEnumValueEntries(IEnumArgumentType type) { var values = type.GetValues() .Where(v => !v.Disallowed && !v.Hidden) .OrderBy(v => v.DisplayName) .ToList(); // See if we can collapse the values onto one entry. if (values.All(v => string.IsNullOrEmpty(v.Description) && v.ShortName == null)) { return(new[] { new ColoredMultistring($"{{{string.Join(", ", values.Select(v => v.DisplayName))}}}") }); } else { return(values.Select(FormatEnumValueInfo)); } }
private IEnumerable <ColoredMultistring> GetEnumValueEntries( int currentMaxWidth, IEnumArgumentType type) { var values = type.GetValues() .Where(v => !v.Disallowed && !v.Hidden) .OrderBy(v => v.DisplayName) .ToList(); // See if we can collapse the values onto one entry. if (values.All(v => string.IsNullOrEmpty(v.Description) && v.ShortName == null)) { return(new[] { new ColoredMultistring($"{{{string.Join(", ", values.Select(v => v.DisplayName))}}}") }); } else { var entries = values.Select(GetEnumValueInfo).ToList(); var maxLengthOfParameterSyntax = entries.Count > 0 ? entries.Max(e => e.Syntax.Length) : 0; return(FormatParameterEntries(currentMaxWidth, entries, maxLengthOfParameterSyntax)); } }