BadScript 2
Loading...
Searching...
No Matches
NameInfo.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
5namespace CommandLine
6{
10 public sealed class NameInfo : IEquatable<NameInfo>
11 {
16 public static readonly NameInfo EmptyName = new NameInfo(string.Empty, string.Empty);
17
18 internal NameInfo(string shortName, string longName)
19 {
20 if (shortName == null)
21 {
22 throw new ArgumentNullException("shortName");
23 }
24
25 if (longName == null)
26 {
27 throw new ArgumentNullException("longName");
28 }
29
30 LongName = longName;
31 ShortName = shortName;
32 }
33
37 public string ShortName { get; }
38
42 public string LongName { get; }
43
47 public string NameText => ShortName.Length > 0 && LongName.Length > 0 ? ShortName + ", " + LongName :
48 ShortName.Length > 0 ? ShortName : LongName;
49
50#region IEquatable<NameInfo> Members
51
64 public bool Equals(NameInfo other)
65 {
66 if (other == null)
67 {
68 return false;
69 }
70
71 return ShortName.Equals(other.ShortName) && LongName.Equals(other.LongName);
72 }
73
74#endregion
75
86 public override bool Equals(object obj)
87 {
88 NameInfo other = obj as NameInfo;
89
90 if (other != null)
91 {
92 return Equals(other);
93 }
94
95 return base.Equals(obj);
96 }
97
102 public override int GetHashCode()
103 {
104 return new { ShortName, LongName }.GetHashCode();
105 }
106 }
107}
Models name information, used in CommandLine.Error instances.
Definition NameInfo.cs:11
override int GetHashCode()
Serves as a hash function for a particular type.
Definition NameInfo.cs:102
string NameText
Gets a formatted text with unified name information.
Definition NameInfo.cs:47
static readonly NameInfo EmptyName
Represents an empty name information. Used when CommandLine.Error are tied to values,...
Definition NameInfo.cs:16
NameInfo(string shortName, string longName)
Definition NameInfo.cs:18
string LongName
Gets the long name of the name information.
Definition NameInfo.cs:42
string ShortName
Gets the short name of the name information.
Definition NameInfo.cs:37
override bool Equals(object obj)
Determines whether the specified System.Object is equal to the current System.Object.
Definition NameInfo.cs:86
bool Equals(NameInfo other)
Returns a value that indicates whether the current instance and a specified CommandLine....
Definition NameInfo.cs:64