-
Notifications
You must be signed in to change notification settings - Fork 481
/
Copy pathNameInfo.cs
101 lines (89 loc) · 3.72 KB
/
NameInfo.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
using System;
using CommandLine.Core;
namespace CommandLine
{
/// <summary>
/// Models name information, used in <see cref="CommandLine.Error"/> instances.
/// </summary>
public sealed class NameInfo : IEquatable<NameInfo>
{
/// <summary>
/// Represents an empty name information. Used when <see cref="CommandLine.Error"/> are tied to values,
/// rather than options.
/// </summary>
public static readonly NameInfo EmptyName = new NameInfo(string.Empty, string.Empty);
private readonly string longName;
private readonly string shortName;
internal NameInfo(string shortName, string longName)
{
if (shortName == null) throw new ArgumentNullException("shortName");
if (longName == null) throw new ArgumentNullException("longName");
this.longName = longName;
this.shortName = shortName;
}
/// <summary>
/// Gets the short name of the name information.
/// </summary>
public string ShortName
{
get { return shortName; }
}
/// <summary>
/// Gets the long name of the name information.
/// </summary>
public string LongName
{
get { return longName; }
}
/// <summary>
/// Gets a formatted text with unified name information.
/// </summary>
public string NameText
{
get
{
return ShortName.Length > 0 && LongName.Length > 0
? ShortName + ", " + LongName
: ShortName.Length > 0
? ShortName
: LongName;
}
}
/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="System.Object"/>.
/// </summary>
/// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="System.Object"/>.</param>
/// <returns><value>true</value> if the specified <see cref="System.Object"/> is equal to the current <see cref="System.Object"/>; otherwise, <value>false</value>.</returns>
public override bool Equals(object obj)
{
var other = obj as NameInfo;
if (other != null)
{
return Equals(other);
}
return base.Equals(obj);
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <remarks>A hash code for the current <see cref="System.Object"/>.</remarks>
public override int GetHashCode()
{
return new { ShortName, LongName }.GetHashCode();
}
/// <summary>
/// Returns a value that indicates whether the current instance and a specified <see cref="CommandLine.NameInfo"/> have the same value.
/// </summary>
/// <param name="other">The <see cref="CommandLine.NameInfo"/> instance to compare.</param>
/// <returns><value>true</value> if this instance of <see cref="CommandLine.NameInfo"/> and <paramref name="other"/> have the same value; otherwise, <value>false</value>.</returns>
public bool Equals(NameInfo other)
{
if (other == null)
{
return false;
}
return ShortName.Equals(other.ShortName) && LongName.Equals(other.LongName);
}
}
}