-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCertifiedValueArgument.cs
More file actions
84 lines (76 loc) · 3.9 KB
/
CertifiedValueArgument.cs
File metadata and controls
84 lines (76 loc) · 3.9 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
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
namespace CommandLineParser.Arguments
{
/// <summary>
/// CertifiedValueArgument is a base class for all arguments that have other limitations and restrictions (defined
/// int <see cref="Certify"/> function) on their values apart from the value
/// being of a certain type (<typeparamref name="TValue"/>).
/// </summary>
/// <typeparam name="TValue">Type of the value</typeparam>
/// <seealso cref="BoundedValueArgument{TValue}"/>
/// <seealso cref="EnumeratedValueArgument{TValue}"/>
/// <include file='..\Doc\CommandLineParser.xml' path='CommandLineParser/Arguments/CertifiedValueArgument/*'/>
public abstract class CertifiedValueArgument<TValue> : ValueArgument<TValue>
{
#region constructor
/// <summary>
/// Creates new certified value argument with a <see cref="Argument.ShortName">short name</see>.
/// </summary>
/// <param name="shortName">Short name of the argument</param>
protected CertifiedValueArgument(char shortName) : base(shortName) { }
/// <summary>
/// Creates new certified value argument with a <see cref="Argument.LongName">long name</see>.
/// </summary>
/// <param name="longName">Long name of the argument</param>
protected CertifiedValueArgument(string longName) : base(longName) { }
/// <summary>
/// Creates new certified value argument with a <see cref="Argument.ShortName">short name</see>and <see cref="Argument.LongName">long name</see>.
/// </summary>
/// <param name="shortName">Short name of the argument</param>
/// <param name="longName">Long name of the argument </param>
protected CertifiedValueArgument(char shortName, string longName)
: base(shortName, longName) { }
/// <summary>
/// Creates new certified value argument with a <see cref="Argument.ShortName">short name</see>,
/// <see cref="Argument.LongName">long name</see> and <see cref="Argument.Description">description</see>
/// </summary>
/// <param name="shortName">Short name of the argument</param>
/// <param name="longName">Long name of the argument </param>
/// <param name="description">description of the argument</param>
protected CertifiedValueArgument(char shortName, string longName, string description)
: base(shortName, longName, description) { }
#endregion
/// <summary>
/// This method reads the argument and the following string representing the value of the argument.
/// This string is then converted to <typeparamref name="TValue"/> (using built-in <typeparamref name="TValue"/>.Parse
/// method for built-in types or using <see cref="ValueArgument{TValue}.ConvertValueHandler"/> for user types).
/// After successful conversion, validation <see cref="Certify"/> method is called
/// </summary>
/// <param name="args">command line arguments</param>
/// <param name="i">index to the args array, where this argument occurred. The index to the next argument
/// after the argument is processed. </param>
/// <seealso cref="ValueArgument{TValue}.ConvertValueHandler"/>
public override void Parse(IList<string> args, ref int i)
{
base.Parse(args, ref i);
if (AllowMultiple)
{
foreach (TValue val in Values)
{
Certify(val);
}
}
else
{
Certify(Value);
}
}
/// <summary>
/// Checks for argument specific
/// restriction and limitations. Exceptions are thrown when these are not met.
/// </summary>
/// <param name="value">value to certify</param>
protected abstract void Certify(TValue value);
}
}