public Argument(ICreateArgumentCatagory catagoryCreator, IArgumentCatagory <TOptions> currentCatagory, PropertyInfo property) { IsEnum = typeof(Enum).GetTypeInfo().IsAssignableFrom(typeof(TArgument).GetTypeInfo()); if (!IsEnum) { if (!ArgumentParser.SupportedTypes.Contains(typeof(TArgument))) { throw new ArgumentException( $"{typeof(TArgument).Name} is not supported as an argument type for '{property.Name}' on catagory '{typeof(TOptions).Name}'. Please use only one of the supported types as found in {nameof(ArgumentParser.SupportedTypes)}", nameof(TArgument)); } } if (property.GetMethod == null || property.SetMethod == null) { throw new ArgumentException( $"Property '{property.Name}' must have both a get and set accessor on catagory '{typeof(TOptions).Name}'.", nameof(property)); } _catagoryCreator = catagoryCreator; _currentCatagory = currentCatagory; Property = property; if (typeof(TArgument).GetTypeInfo().GetCustomAttribute <FlagsAttribute>() != null) { IsFlags = true; } ArgumentName = ArgumentHelper.DefaultArgumentToString(property.Name); ArgumentType = typeof(TArgument); }
public MultiArgument(ICreateArgumentCatagory catagoryCreator, IArgumentCatagory <TOptions> currentCatagory, PropertyInfo property) : base(catagoryCreator, currentCatagory, property) { if (typeof(TArgument) == typeof(bool)) { throw new ArgumentException( $"{typeof(TArgument).Name} is not supported as an argument type for '{property.Name}' on catagory '{typeof(TOptions).Name}'. Please use int type with {nameof(Countable)} function instead", nameof(TArgument)); } if (IsFlags) { throw new ArgumentException( $"Flags enum type is not supported as a multi-argument type for '{property.Name}' on catagory '{typeof(TOptions).Name}'. Either use non flag enum or use a normal Argument", nameof(TArgument)); } IsMultiple = true; }
public ArgumentCatagory(ICreateArgumentCatagory catagoryCreator, string name) { _catagoryCreator = catagoryCreator; CatagoryName = ArgumentHelper.FormatModuleName(name); }