using System;
using System.Reflection;
using JetBrains.Annotations;
using NugetForUnity.Helper;
namespace NugetForUnity.Configuration
{
///
/// Represents a plugin in the configuration.
///
internal sealed class NugetForUnityPluginId : IEquatable
{
///
/// Initializes a new instance of the class.
///
/// Name of plugin assembly.
/// Path to the plugin assembly.
internal NugetForUnityPluginId([NotNull] string name, [NotNull] string path)
{
Name = name;
Path = System.IO.Path.IsPathRooted(path) ? PathHelper.GetRelativePath(UnityPathHelper.AbsoluteProjectPath, path) : path;
}
///
/// Initializes a new instance of the class.
///
/// Plugin assembly.
internal NugetForUnityPluginId([NotNull] Assembly assembly)
: this(assembly.GetName().Name, assembly.Location)
{
}
///
/// Gets the name of the Plugin assembly.
///
[NotNull]
internal string Name { get; }
///
/// Gets the path to the plugin assembly.
///
[NotNull]
internal string Path { get; }
///
/// Checks to see if the left is equal to the right.
/// They are equal if the Id and the Version match.
///
/// The left to compare.
/// The right to compare.
/// True if the left is equal to the right.
public static bool operator ==([CanBeNull] NugetForUnityPluginId left, [CanBeNull] NugetForUnityPluginId right)
{
return Equals(left, right);
}
///
/// Checks to see if the left is not equal to the right.
/// They are equal if the Id and the Version match.
///
/// The left to compare.
/// The right to compare.
/// True if the left is equal to the right.
public static bool operator !=([CanBeNull] NugetForUnityPluginId left, [CanBeNull] NugetForUnityPluginId right)
{
return !Equals(left, right);
}
///
public bool Equals(NugetForUnityPluginId other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase) &&
string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase);
}
///
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != GetType())
{
return false;
}
return Equals((NugetForUnityPluginId)obj);
}
///
public override int GetHashCode()
{
unchecked
{
return (StringComparer.OrdinalIgnoreCase.GetHashCode(Name) * 397) ^ StringComparer.OrdinalIgnoreCase.GetHashCode(Path);
}
}
}
}