Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/21/12 14:41:56 (12 years ago)
Author:
jkarder
Message:

#1926: refactored argument handling infrastructure based on the changes suggested by ascheibe in comment:7:ticket:1926

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/ArgumentHandling/ArgumentHandling.cs

    r8563 r8677  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    2627namespace HeuristicLab.PluginInfrastructure {
    2728  public static class ArgumentHandling {
    28     public const string StartToken = "start";
    29 
    3029    public static IArgument[] GetArguments(string[] args) {
    3130      var arguments = new HashSet<IArgument>();
     31      var exceptions = new List<Exception>();
     32
    3233      foreach (var entry in args) {
    3334        var argument = ParseArgument(entry);
    3435        if (argument != null && argument.Valid) arguments.Add(argument);
     36        else exceptions.Add(new ArgumentException(string.Format("The argument \"{0}\" is invalid.", entry)));
    3537      }
     38
     39      if (exceptions.Any()) throw new AggregateException("One or more arguments are invalid.", exceptions);
    3640      return arguments.ToArray();
    3741    }
    3842
    3943    private static Argument ParseArgument(string entry) {
    40       var regex = new Regex("^/[a-z]+(:[A-Za-z0-9 ]+)?$");
     44      var regex = new Regex(@"^/[a-z]+(:[A-Za-z0-9\s]+)?$");
    4145      if (!regex.IsMatch(entry)) return null;
    4246      entry = entry.Remove(0, 1);
     
    4448      string key = parts[0];
    4549      string value = parts.Length == 2 ? parts[1].Trim() : string.Empty;
    46       switch (key) {
    47         case StartToken: return new StartArgument(value);
    48         default: return null;
    49       }
     50      return new Argument(key.ToLower(), value);
    5051    }
    5152  }
Note: See TracChangeset for help on using the changeset viewer.