Ejemplo n.º 1
0
        public IOptDefinitionFluentBuilder <TTarget> AddOpt(Expression <Func <TTarget, bool> > selector)
        {
            var opt = new OptDefinition <TTarget>(selector);

            this._opts.Add(opt);
            return(new OptDefinitionFluentBuilder <TTarget>(opt));
        }
 public OptWithArgumentDefinitionFluentBuilder(OptDefinition <T> opt) : base(opt)
 {
 }
 public OptDefinitionFluentBuilder(OptDefinition <T> opt)
 {
     _opt = opt;
 }
        public static string ParseArgument <T>(
            this OptDefinition <T> opt,
            string[] args,
            ref int i,
            string match) where T : new()
        {
            string arg = args[i];

            switch (opt.ArgumentFormat)
            {
            case OptDefinitionArgumentFormat.None:
            {
                throw new GetOptException($"{OptDefinitionArgumentFormat.None} can't be parsed");
            }

            case OptDefinitionArgumentFormat.NextArg:
            {
                if (args.Length <= i + 1)
                {
                    if (opt.Argument == OptDefinitionArgument.Optional)
                    {
                        return(null);
                    }
                    else
                    {
                        throw new MissingArgumentException(opt.ArgumentName);
                    }
                }
                return(args[++i]);
            }

            case OptDefinitionArgumentFormat.EqualSign:
            {
                var r = arg.Substring(match.Length);
                if (r.StartsWith("="))
                {
                    return(r.Substring(1));
                }
                throw new ArgumentFormatException(
                          $"value '{args[i]}' can't be matched as '{opt.ArgumentName}' {OptDefinitionArgumentFormat.EqualSign}");
            }

            case OptDefinitionArgumentFormat.Close:
            {
                return(arg.Substring(match.Length));
            }

            case OptDefinitionArgumentFormat.Parentheses:
            {
                var r = arg.Substring(match.Length);
                if (r.StartsWith("(") && r.EndsWith(")"))
                {
                    return(r.Substring(1, r.Length - 2));
                }
                throw new ArgumentFormatException(
                          $"value '{args[i]}' can't be matched as '{opt.ArgumentName}' {OptDefinitionArgumentFormat.Parentheses}");
            }

            case OptDefinitionArgumentFormat.SquareBrackets:
            {
                var r = arg.Substring(match.Length);
                if (r.StartsWith("[") && r.EndsWith("]"))
                {
                    return(r.Substring(1, r.Length - 2));
                }
                throw new ArgumentFormatException(
                          $"value '{args[i]}' can't be matched as '{opt.ArgumentName}' {OptDefinitionArgumentFormat.SquareBrackets}");
            }

            case OptDefinitionArgumentFormat.Braces:
            {
                var r = arg.Substring(match.Length);
                if (r.StartsWith("{") && r.EndsWith("}"))
                {
                    return(r.Substring(1, r.Length - 2));
                }
                throw new ArgumentFormatException(
                          $"value '{args[i]}' can't be matched as '{opt.ArgumentName}' {OptDefinitionArgumentFormat.Braces}");
            }

            case OptDefinitionArgumentFormat.AngleBrackets:
            {
                var r = arg.Substring(match.Length);
                if (r.StartsWith("<") && r.EndsWith(">"))
                {
                    return(r.Substring(1, r.Length - 2));
                }
                throw new ArgumentFormatException(
                          $"value '{args[i]}' can't be matched as '{opt.ArgumentName}' {OptDefinitionArgumentFormat.AngleBrackets}");
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }