// 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
{
///
/// Models name information, used in instances.
///
public sealed class NameInfo : IEquatable
{
///
/// Represents an empty name information. Used when are tied to values,
/// rather than options.
///
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;
}
///
/// Gets the short name of the name information.
///
public string ShortName
{
get { return shortName; }
}
///
/// Gets the long name of the name information.
///
public string LongName
{
get { return longName; }
}
///
/// Gets a formatted text with unified name information.
///
public string NameText
{
get
{
return ShortName.Length > 0 && LongName.Length > 0
? ShortName + ", " + LongName
: ShortName.Length > 0
? ShortName
: LongName;
}
}
///
/// Determines whether the specified is equal to the current .
///
/// The to compare with the current .
/// true if the specified is equal to the current ; otherwise, false.
public override bool Equals(object obj)
{
var other = obj as NameInfo;
if (other != null)
{
return Equals(other);
}
return base.Equals(obj);
}
///
/// Serves as a hash function for a particular type.
///
/// A hash code for the current .
public override int GetHashCode()
{
return new { ShortName, LongName }.GetHashCode();
}
///
/// Returns a value that indicates whether the current instance and a specified have the same value.
///
/// The instance to compare.
/// true if this instance of and have the same value; otherwise, false.
public bool Equals(NameInfo other)
{
if (other == null)
{
return false;
}
return ShortName.Equals(other.ShortName) && LongName.Equals(other.LongName);
}
}
}