BadScript 2
Loading...
Searching...
No Matches
OptionAttribute.cs
Go to the documentation of this file.
1// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2
3using System;
4
6
7namespace CommandLine
8{
12 [AttributeUsage(AttributeTargets.Property)]
13 public sealed class OptionAttribute : BaseAttribute
14 {
15 private string setName;
16
17 private OptionAttribute(string shortName, string longName)
18 {
19 if (shortName == null)
20 {
21 throw new ArgumentNullException("shortName");
22 }
23
24 if (longName == null)
25 {
26 throw new ArgumentNullException("longName");
27 }
28
29 ShortName = shortName;
30 LongName = longName;
31 setName = string.Empty;
32 Separator = '\0';
33 }
34
40 : this(string.Empty, string.Empty) { }
41
46 public OptionAttribute(string longName)
47 : this(string.Empty, longName) { }
48
54 public OptionAttribute(char shortName, string longName)
55 : this(shortName.ToOneCharString(), longName) { }
56
61 public OptionAttribute(char shortName)
62 : this(shortName.ToOneCharString(), string.Empty) { }
63
67 public string LongName { get; }
68
72 public string ShortName { get; }
73
77 public string SetName
78 {
79 get => setName;
80 set
81 {
82 if (value == null)
83 {
84 throw new ArgumentNullException("value");
85 }
86
87 setName = value;
88 }
89 }
90
96 public bool FlagCounter { get; set; }
97
102 public char Separator { get; set; }
103
108 public string Group { get; set; } = string.Empty;
109 }
110}
Models a base attribute to define command line syntax.
Models an option specification.
OptionAttribute(string shortName, string longName)
OptionAttribute(string longName)
Initializes a new instance of the CommandLine.OptionAttribute class.
string Group
Gets or sets the option group name. When one or more options are grouped, at least one of them should...
OptionAttribute(char shortName, string longName)
Initializes a new instance of the CommandLine.OptionAttribute class.
OptionAttribute()
Initializes a new instance of the CommandLine.OptionAttribute class. The default long name will be in...
OptionAttribute(char shortName)
Initializes a new instance of the CommandLine.OptionAttribute class.
char Separator
When applying attribute to System.Collections.Generic.IEnumerable<T> target properties,...
string SetName
Gets or sets the option's mutually exclusive set name.
bool FlagCounter
If true, this is an int option that counts how many times a flag was set (e.g. "-v -v -v" or "-vvv" w...
string ShortName
Gets a short name of this command line option, made of one character.
string LongName
Gets long name of this command line option. This name is usually a single english word.