2023-08-11 15:51:20 +01:00
|
|
|
namespace OliverBooth.Data.Web;
|
2023-08-08 21:03:41 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a MediaWiki-style template.
|
|
|
|
/// </summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
public sealed class Template : ITemplate, IEquatable<Template>
|
2023-08-08 21:03:41 +01:00
|
|
|
{
|
2023-08-13 13:27:44 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
public string FormatString { get; internal set; } = string.Empty;
|
2023-08-08 21:03:41 +01:00
|
|
|
|
2023-08-13 13:27:44 +01:00
|
|
|
/// <inheritdoc />
|
2023-08-08 21:03:41 +01:00
|
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
|
|
|
|
/// <summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
/// Returns a value indicating whether two instances of <see cref="Template" /> are equal.
|
2023-08-08 21:03:41 +01:00
|
|
|
/// </summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
/// <param name="left">The first instance of <see cref="Template" /> to compare.</param>
|
|
|
|
/// <param name="right">The second instance of <see cref="Template" /> to compare.</param>
|
2023-08-08 21:03:41 +01:00
|
|
|
/// <returns>
|
|
|
|
/// <see langword="true" /> if <paramref name="left" /> and <paramref name="right" /> are equal; otherwise,
|
|
|
|
/// <see langword="false" />.
|
|
|
|
/// </returns>
|
2023-08-13 13:27:44 +01:00
|
|
|
public static bool operator ==(Template? left, Template? right) => Equals(left, right);
|
2023-08-08 21:03:41 +01:00
|
|
|
|
|
|
|
/// <summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
/// Returns a value indicating whether two instances of <see cref="Template" /> are not equal.
|
2023-08-08 21:03:41 +01:00
|
|
|
/// </summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
/// <param name="left">The first instance of <see cref="Template" /> to compare.</param>
|
|
|
|
/// <param name="right">The second instance of <see cref="Template" /> to compare.</param>
|
2023-08-08 21:03:41 +01:00
|
|
|
/// <returns>
|
|
|
|
/// <see langword="true" /> if <paramref name="left" /> and <paramref name="right" /> are not equal; otherwise,
|
|
|
|
/// <see langword="false" />.
|
|
|
|
/// </returns>
|
2023-08-13 13:27:44 +01:00
|
|
|
public static bool operator !=(Template? left, Template? right) => !(left == right);
|
2023-08-08 21:03:41 +01:00
|
|
|
|
|
|
|
/// <summary>
|
2023-08-13 13:27:44 +01:00
|
|
|
/// Returns a value indicating whether this instance of <see cref="Template" /> is equal to another
|
2023-08-08 21:03:41 +01:00
|
|
|
/// instance.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="other">An instance to compare with this instance.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// <see langword="true" /> if <paramref name="other" /> is equal to this instance; otherwise,
|
|
|
|
/// <see langword="false" />.
|
|
|
|
/// </returns>
|
2023-08-13 13:27:44 +01:00
|
|
|
public bool Equals(Template? other)
|
2023-08-08 21:03:41 +01:00
|
|
|
{
|
|
|
|
if (ReferenceEquals(null, other)) return false;
|
|
|
|
if (ReferenceEquals(this, other)) return true;
|
|
|
|
return Name == other.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Returns a value indicating whether this instance is equal to a specified object.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="obj">An object to compare with this instance.</param>
|
|
|
|
/// <returns>
|
2023-08-13 13:27:44 +01:00
|
|
|
/// <see langword="true" /> if <paramref name="obj" /> is an instance of <see cref="Template" /> and
|
2023-08-08 21:03:41 +01:00
|
|
|
/// equals the value of this instance; otherwise, <see langword="false" />.
|
|
|
|
/// </returns>
|
|
|
|
public override bool Equals(object? obj)
|
|
|
|
{
|
2023-08-13 13:27:44 +01:00
|
|
|
return ReferenceEquals(this, obj) || obj is Template other && Equals(other);
|
2023-08-08 21:03:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the hash code for this instance.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The hash code.</returns>
|
|
|
|
public override int GetHashCode()
|
|
|
|
{
|
|
|
|
// ReSharper disable once NonReadonlyMemberInGetHashCode
|
|
|
|
return Name.GetHashCode();
|
|
|
|
}
|
|
|
|
}
|