blob: 6ca902dad497d496ee6141702f4a8f0c49667694 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// Copyright © Microsoft Corporation.
// This source file is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other 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;
[CLSCompliant(false)]
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);
}
}
|