Skip to content

Commit 4d5d33a

Browse files
committed
Adding a base attr class
1 parent 8093b51 commit 4d5d33a

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

src/CommandLine/BaseAttribute.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace CommandLine
7+
{
8+
public abstract class BaseAttribute
9+
{
10+
private int min;
11+
private int max;
12+
private object @default;
13+
14+
protected BaseAttribute()
15+
{
16+
min = -1;
17+
max = -1;
18+
}
19+
20+
/// <summary>
21+
/// Gets or sets a value indicating whether a command line option is required.
22+
/// </summary>
23+
public bool Required
24+
{
25+
get;
26+
set;
27+
}
28+
29+
/// <summary>
30+
/// When applied to <see cref="System.Collections.Generic.IEnumerable{T}"/> properties defines
31+
/// the lower range of items.
32+
/// </summary>
33+
/// <remarks>If not set, no lower range is enforced.</remarks>
34+
public int Min
35+
{
36+
get { return min; }
37+
set
38+
{
39+
if (value < 0)
40+
{
41+
throw new ArgumentNullException("value");
42+
}
43+
44+
min = value;
45+
}
46+
}
47+
48+
/// <summary>
49+
/// When applied to <see cref="System.Collections.Generic.IEnumerable{T}"/> properties defines
50+
/// the upper range of items.
51+
/// </summary>
52+
/// <remarks>If not set, no upper range is enforced.</remarks>
53+
public int Max
54+
{
55+
get { return max; }
56+
set
57+
{
58+
if (value < 0)
59+
{
60+
throw new ArgumentNullException("value");
61+
}
62+
63+
max = value;
64+
}
65+
}
66+
67+
/// <summary>
68+
/// Gets or sets mapped property default value.
69+
/// </summary>
70+
public object Default
71+
{
72+
get { return @default; }
73+
set
74+
{
75+
if (value == null)
76+
{
77+
throw new ArgumentNullException("value");
78+
}
79+
80+
@default = value;
81+
}
82+
}
83+
}
84+
}

src/CommandLine/CommandLine.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="..\SharedAssemblyInfo.cs">
5959
<Link>Properties\SharedAssemblyInfo.cs</Link>
6060
</Compile>
61+
<Compile Include="BaseAttribute.cs" />
6162
<Compile Include="Core\ArgumentsExtension.cs" />
6263
<Compile Include="Core\KeyValuePairHelper.cs" />
6364
<Compile Include="Core\PreprocessorGuards.cs" />

0 commit comments

Comments
 (0)