using System; using System.Collections.Specialized; namespace SPSolutions.SharePoint.Administration { public class CommandLineParameter { private string defaultValue; private string helpMessage; private bool isRequired; private string name; private bool userTypedIn; private CommandLineParameterValidator validator; private string value; public string DefaultValue { get { return this.defaultValue; } } public string HelpMessage { get { return this.helpMessage; } } public bool IsRequired { get { return this.isRequired; } } public string Name { get { return this.name; } } public bool UserTypedIn { get { return this.userTypedIn; } } public string Value { get { return this.value; } } public CommandLineParameter(string name, bool isRequired) : this(name, isRequired, null, null, null) { } public CommandLineParameter(string name, bool isRequired, string defaultValue) : this(name, isRequired, defaultValue, null, null) { } public CommandLineParameter(string name, bool isRequired, string defaultValue, CommandLineParameterValidator validator, string helpMessage) { this.name = name; this.isRequired = isRequired; this.defaultValue = defaultValue; this.validator = validator; if (!string.IsNullOrEmpty(helpMessage)) { this.helpMessage = helpMessage; } } public void Initialize(StringDictionary keyValues) { this.value = keyValues[this.name]; this.userTypedIn = (this.value != null); if (!this.userTypedIn) { this.value = this.defaultValue; } } public bool Validate() { return this.validator == null || this.validator.Validate(this.value); } } }