Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/05/12 17:13:25 (12 years ago)
Author:
jkarder
Message:

#1926:

Location:
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling
Files:
3 added
3 deleted
3 copied
1 moved

Legend:

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

    r8741 r8748  
    2121
    2222namespace HeuristicLab.PluginInfrastructure {
    23   public class Argument : IArgument {
    24     public const string START = "start";
    25 
    26     public string Token { get; private set; }
    27     public string Value { get; private set; }
    28     public bool Valid { get { return !string.IsNullOrEmpty(Value); } }
    29 
    30     public Argument(string token, string value) {
    31       Token = token;
    32       Value = value;
    33     }
     23  public abstract class CommandLineArgument<T> : ICommandLineArgument<T> {
     24    object ICommandLineArgument.Value { get { return Value; } }
     25    public T Value { get; protected set; }
     26    public bool Valid { get { return CheckValidity(); } }
    3427
    3528    public override bool Equals(object obj) {
    3629      if (obj == null || this.GetType() != obj.GetType()) return false;
    37       var other = (Argument)obj;
    38       return this.Token == other.Token && this.Value == other.Value;
     30      var other = (ICommandLineArgument<T>)obj;
     31      return this.Value.Equals(other.Value);
    3932    }
    4033
    4134    public override int GetHashCode() {
    42       return GetType().GetHashCode();
     35      return GetType().GetHashCode() ^ Value.GetHashCode();
    4336    }
     37
     38    protected abstract bool CheckValidity();
    4439  }
    4540}
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgumentHandling.cs

    r8741 r8748  
    2626
    2727namespace HeuristicLab.PluginInfrastructure {
    28   public static class ArgumentHandling {
    29     public static IArgument[] GetArguments(string[] args) {
    30       var arguments = new HashSet<IArgument>();
     28  public static class CommandLineArgumentHandling {
     29    public static ICommandLineArgument[] GetArguments(string[] args) {
     30      var arguments = new HashSet<ICommandLineArgument>();
    3131      var exceptions = new List<Exception>();
    3232
     
    4141    }
    4242
    43     private static Argument ParseArgument(string entry) {
    44       var regex = new Regex(@"^/[a-z]+(:[A-Za-z0-9\s]+)?$");
     43    private static ICommandLineArgument ParseArgument(string entry) {
     44      var regex = new Regex(@"^/[A-Za-z]+(:[A-Za-z0-9\s]+)?$");
    4545      if (!regex.IsMatch(entry)) return null;
    4646      entry = entry.Remove(0, 1);
    4747      var parts = entry.Split(':');
    48       string key = parts[0];
     48      string key = parts[0].Trim();
    4949      string value = parts.Length == 2 ? parts[1].Trim() : string.Empty;
    50       return new Argument(key.ToLower(), value);
     50      switch (key) {
     51        case StartArgument.TOKEN: return new StartArgument(value);
     52        case HideStarterArgument.TOKEN: return new HideStarterArgument(value);
     53        default: return null;
     54      }
    5155    }
    5256  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/ICommandLineArgument.cs

    r8741 r8748  
    2121
    2222namespace HeuristicLab.PluginInfrastructure {
    23   public interface IArgument {
    24     string Token { get; }
    25     string Value { get; }
     23  public interface ICommandLineArgument {
     24    object Value { get; }
    2625    bool Valid { get; }
    2726  }
     27
     28  public interface ICommandLineArgument<out T> : ICommandLineArgument {
     29    new T Value { get; }
     30  }
    2831}
Note: See TracChangeset for help on using the changeset viewer.