Beispiel #1
0
        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 void ArgumentCatagoryNameMethodSetsName()
        {
            IArgumentCatagory <NoOptions> cat = ArgumentParser.Create("app").CreateArgumentCatagory <NoOptions>();

            cat.Name("CustomName");

            Assert.Equal("CustomName", cat.CatagoryName);
        }
        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 void ArgumentCatagoryWithMultiArgumentOnSamePropertyThrowArgumentException()
        {
            IArgumentCatagory <MultiOptions> catagory = ArgumentParser.Create("app").CreateArgumentCatagory <MultiOptions>();

            Assert.Throws <ArgumentException>(() => catagory.WithMultiArgument(x => x.Boolean).WithMultiArgument(x => x.Boolean));
        }
        public void ArgumentCatagoryWithArgumentIsTypeIArgument_T_()
        {
            IArgumentCatagory <BasicOptions> catagory = ArgumentParser.Create("app").CreateArgumentCatagory <BasicOptions>();

            Assert.IsAssignableFrom <IArgument <BasicOptions, bool> >(catagory.WithArgument(x => x.Boolean));
        }
        public void ArgumentCatagoryWithArgumentNotNull()
        {
            IArgumentCatagory <BasicOptions> catagory = ArgumentParser.Create("app").CreateArgumentCatagory <BasicOptions>();

            Assert.NotNull(catagory.WithArgument(x => x.Boolean));
        }