using System;
using System.Collections.Generic;
using System.Globalization;
namespace MediaBrowser.Common.Plugins
{
///
/// Local plugin struct.
///
public class LocalPlugin : IEquatable
{
///
/// Initializes a new instance of the class.
///
/// The plugin id.
/// The plugin name.
/// The plugin version.
/// The plugin path.
public LocalPlugin(Guid id, string name, Version version, string path)
{
Id = id;
Name = name;
Version = version;
Path = path;
DllFiles = new List();
}
///
/// Gets the plugin id.
///
public Guid Id { get; }
///
/// Gets the plugin name.
///
public string Name { get; }
///
/// Gets the plugin version.
///
public Version Version { get; }
///
/// Gets the plugin path.
///
public string Path { get; }
///
/// Gets the list of dll files for this plugin.
///
public List DllFiles { get; }
///
/// == operator.
///
/// Left item.
/// Right item.
/// Comparison result.
public static bool operator ==(LocalPlugin left, LocalPlugin right)
{
return left.Equals(right);
}
///
/// != operator.
///
/// Left item.
/// Right item.
/// Comparison result.
public static bool operator !=(LocalPlugin left, LocalPlugin right)
{
return !left.Equals(right);
}
///
/// Compare two .
///
/// The first item.
/// The second item.
/// Comparison result.
public static int Compare(LocalPlugin a, LocalPlugin b)
{
var compare = string.Compare(a.Name, b.Name, true, CultureInfo.InvariantCulture);
// Id is not equal but name is.
if (a.Id != b.Id && compare == 0)
{
compare = a.Id.CompareTo(b.Id);
}
return compare == 0 ? a.Version.CompareTo(b.Version) : compare;
}
///
public override bool Equals(object obj)
{
return obj is LocalPlugin other && this.Equals(other);
}
///
public override int GetHashCode()
{
return Name.GetHashCode(StringComparison.OrdinalIgnoreCase);
}
///
public bool Equals(LocalPlugin other)
{
return Name.Equals(other.Name, StringComparison.OrdinalIgnoreCase)
&& Id.Equals(other.Id);
}
}
}