diff options
Diffstat (limited to 'tools/Sandcastle/Source/CommandLine/Option.cs')
-rw-r--r-- | tools/Sandcastle/Source/CommandLine/Option.cs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tools/Sandcastle/Source/CommandLine/Option.cs b/tools/Sandcastle/Source/CommandLine/Option.cs new file mode 100644 index 0000000..fb9ed00 --- /dev/null +++ b/tools/Sandcastle/Source/CommandLine/Option.cs @@ -0,0 +1,94 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +using System; +using System.IO; +using System.Collections.Generic; + +namespace Microsoft.Ddue.Tools.CommandLine { + + public abstract class Option { + + internal bool processed; + + protected bool present; + protected object value; + private string description; + + // Data Members + + private string name; + private bool required; + + // Constructors + + protected Option(string name) { + foreach (char character in name) { + if (!(Char.IsLetter(character) || (character == '?'))) throw new ArgumentException("Names must consist of letters.", "name"); + } + this.name = name; + } + + protected Option(string name, string description) : this(name) { + this.description = description; + } + + protected Option(string name, string description, bool required) : this(name, description) { + this.required = required; + } + + public string Description { + get { + return (description); + } + set { + if (processed) throw new InvalidOperationException(); + description = value; + } + } + + public virtual bool IsPresent { + get { + if (!processed) throw new InvalidOperationException(); + return (present); + } + } + + public bool IsRequired { + get { + return (required); + } + set { + if (processed) throw new InvalidOperationException(); + required = value; + } + } + + // Accessors + + public string Name { + get { + return (name); + } + set { + if (processed) throw new InvalidOperationException(); + name = value; + } + } + + public virtual Object Value { + get { + if (!processed) throw new InvalidOperationException(); + return (value); + } + } + + // To be implemented by children + + internal abstract ParseResult ParseArgument(string args); + + internal abstract void WriteTemplate(TextWriter writer); + + } + +} |