-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathDomainUser.cs
44 lines (37 loc) · 1.25 KB
/
DomainUser.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
38
39
40
41
42
43
44
using Ookii.CommandLine;
namespace Categories;
// This custom type has a value description, which will be shown in the usage help. There is no
// need to do this for every argument if it's specified on the type.
[ValueDescription("[Domain\\]User")]
class DomainUser
{
public DomainUser(string? domain, string userName)
{
ArgumentNullException.ThrowIfNull(userName);
Domain = domain;
UserName = userName;
}
public DomainUser(string userName)
: this(null, userName)
{
}
public string? Domain { get; }
public string UserName { get; }
public override string ToString()
=> Domain == null ? UserName : $"{Domain}\\{UserName}";
// The CommandLineParser will use this method to convert a string to a DomainUser instance.
// Using a method with ReadOnlySpan<char> is only possible when using the
// GeneratedParserAttribute.
public static DomainUser Parse(ReadOnlySpan<char> value)
{
var index = value.IndexOf('\\');
if (index == -1)
{
return new(value.ToString());
}
else
{
return new(value[0..index].ToString(), value[(index+1)..].ToString());
}
}
}