Пример #1
0
 public ArgumentInfoHash(ArgumentInfo[] argumentInfo)
 {
     innerHash = new Dictionary<string, ArgumentInfo>(argumentInfo.Length);
     foreach (ArgumentInfo info in argumentInfo)
     {
         if (innerHash.ContainsKey(info.Name))
             innerHash[info.Name] = info;
         else
             innerHash.Add(info.Name, info);
     }
 }
Пример #2
0
        public ParsedArguments(string[] args, ArgumentInfo[] validArgumentInfos)
        {
            this.parsedArguments = new Dictionary<string, string>();
            if (args.Length == 0)
            {
                this.Status = ArgumentParseStatus.Success;
                this.Message = "No arguments";
                return;
            }
            ArgumentInfoHash validArguments = new ArgumentInfoHash(validArgumentInfos);

            foreach (string argument in args)
            {
                string arg = argument.Trim();

                if (!arg.StartsWith("/") || !(arg.Length > 1))
                {
                    Message = "Unrecognized argument format: " + arg;
                    Status = ArgumentParseStatus.Error;
                }
                else
                {
                    string[] nameValue = arg.Substring(1, arg.Length - 1).Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
                    string name = string.Empty;
                    if (nameValue.Length > 0)
                        name = nameValue[0];

                    // allow ":" in arg value
                    if (nameValue.Length > 2)
                    {
                        int startIndex = arg.IndexOf(":") + 1;
                        nameValue = new string[] { name, arg.Substring(startIndex, arg.Length - startIndex) };
                    }

                    if (nameValue.Length == 1 && validArguments[name] != null)
                    {
                        if (validArguments[name].AllowNullValue)
                            parsedArguments.Add(name, "true");
                        else
                            Message = "No value specified for " + name;
                    }

                    if (nameValue.Length == 2)
                    {
                        if (validArguments[name] == null)
                        {
                            Message = "Invalid argument name specified";
                            Status = ArgumentParseStatus.Error;
                        }
                        else
                        {
                            if (parsedArguments.ContainsKey(name))
                                parsedArguments[name] = nameValue[1];
                            else
                                parsedArguments.Add(name, nameValue[1]);
                        }
                    }

                }
            }

            if (Status != ArgumentParseStatus.Error)
                Status = ArgumentParseStatus.Success;
        }
Пример #3
0
 //List<string> validArgumentNames;
 public ParsedArguments(string[] args, string[] validArgNames)
     : this(args, ArgumentInfo.FromStringArray(validArgNames))
 {
 }