-
Notifications
You must be signed in to change notification settings - Fork 479
Expand file tree
/
Copy pathBaseAttribute.cs
More file actions
118 lines (105 loc) · 3.61 KB
/
BaseAttribute.cs
File metadata and controls
118 lines (105 loc) · 3.61 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
namespace CommandLine
{
/// <summary>
/// Models a base attribute to define command line syntax.
/// </summary>
public abstract class BaseAttribute : Attribute
{
private int min;
private int max;
private Infrastructure.LocalizableAttributeProperty helpText;
private string metaValue;
private Type resourceType;
/// <summary>
/// Initializes a new instance of the <see cref="CommandLine.BaseAttribute"/> class.
/// </summary>
protected internal BaseAttribute()
{
min = -1;
max = -1;
helpText = new Infrastructure.LocalizableAttributeProperty(nameof(HelpText));
metaValue = string.Empty;
resourceType = null;
}
/// <summary>
/// Gets or sets a value indicating whether a command line option is required.
/// </summary>
public bool Required
{
get;
set;
}
/// <summary>
/// When applied to <see cref="System.Collections.Generic.IEnumerable{T}"/> properties defines
/// the lower range of items.
/// </summary>
/// <remarks>If not set, no lower range is enforced.</remarks>
public int Min
{
get => min;
set
{
if (value < 0)
{
throw new ArgumentNullException(nameof(value));
}
min = value;
}
}
/// <summary>
/// When applied to <see cref="System.Collections.Generic.IEnumerable{T}"/> properties defines
/// the upper range of items.
/// </summary>
/// <remarks>If not set, no upper range is enforced.</remarks>
public int Max
{
get => max;
set
{
if (value < 0)
{
throw new ArgumentNullException(nameof(value));
}
max = value;
}
}
/// <summary>
/// Gets or sets mapped property default value.
/// </summary>
public object Default { get; set; }
/// <summary>
/// Gets or sets a short description of this command line option. Usually a sentence summary.
/// </summary>
public string HelpText
{
get => helpText.Value??string.Empty;
set => helpText.Value = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets or sets mapped property meta value. Usually an uppercase hint of required value type.
/// </summary>
public string MetaValue
{
get => metaValue;
set => metaValue = value ?? throw new ArgumentNullException(nameof(value));
}
/// <summary>
/// Gets or sets a value indicating whether a command line option is visible in the help text.
/// </summary>
public bool Hidden
{
get;
set;
}
/// <summary>
/// Gets or sets the <see cref="System.Type"/> that contains the resources for <see cref="HelpText"/>.
/// </summary>
public Type ResourceType
{
get => resourceType;
set => resourceType = helpText.ResourceType = value;
}
}
}