-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFlagAttribute.cs
37 lines (32 loc) · 1.04 KB
/
FlagAttribute.cs
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
using System;
using CommandLineParser.Exceptions;
namespace CommandLineParser.Attributes
{
[AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
public sealed class FlagAttribute : Attribute
{
private readonly string shortName;
private readonly string name;
public readonly bool required;
public FlagAttribute(string name = null, string shortName = null, bool required = false)
{
this.name = name;
this.required = required;
this.shortName = shortName;
if (!string.IsNullOrWhiteSpace(shortName) && shortName.Length > 1) throw new LengthExceededException(1);
if (!string.IsNullOrWhiteSpace(name)) this.name = this.name.ToLower();
}
public string Name
{
get { return name; }
}
public string ShortName
{
get { return shortName; }
}
public bool Required
{
get { return required; }
}
}
}