- Timestamp:
- 10/05/12 17:13:25 (12 years ago)
- 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 21 21 22 22 namespace 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(); } } 34 27 35 28 public override bool Equals(object obj) { 36 29 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); 39 32 } 40 33 41 34 public override int GetHashCode() { 42 return GetType().GetHashCode() ;35 return GetType().GetHashCode() ^ Value.GetHashCode(); 43 36 } 37 38 protected abstract bool CheckValidity(); 44 39 } 45 40 } -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgumentHandling.cs
r8741 r8748 26 26 27 27 namespace HeuristicLab.PluginInfrastructure { 28 public static class ArgumentHandling {29 public static I Argument[] GetArguments(string[] args) {30 var arguments = new HashSet<I Argument>();28 public static class CommandLineArgumentHandling { 29 public static ICommandLineArgument[] GetArguments(string[] args) { 30 var arguments = new HashSet<ICommandLineArgument>(); 31 31 var exceptions = new List<Exception>(); 32 32 … … 41 41 } 42 42 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]+)?$"); 45 45 if (!regex.IsMatch(entry)) return null; 46 46 entry = entry.Remove(0, 1); 47 47 var parts = entry.Split(':'); 48 string key = parts[0] ;48 string key = parts[0].Trim(); 49 49 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 } 51 55 } 52 56 } -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/ICommandLineArgument.cs
r8741 r8748 21 21 22 22 namespace HeuristicLab.PluginInfrastructure { 23 public interface IArgument { 24 string Token { get; } 25 string Value { get; } 23 public interface ICommandLineArgument { 24 object Value { get; } 26 25 bool Valid { get; } 27 26 } 27 28 public interface ICommandLineArgument<out T> : ICommandLineArgument { 29 new T Value { get; } 30 } 28 31 }
Note: See TracChangeset
for help on using the changeset viewer.