2022-06-20 09:21:08 +02:00
|
|
|
namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource;
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// The serialization result from <see cref="IContentCacheDataSerializer" /> for which the serialized value
|
|
|
|
|
/// will be either a string or a byte[]
|
|
|
|
|
/// </summary>
|
|
|
|
|
public struct ContentCacheDataSerializationResult : IEquatable<ContentCacheDataSerializationResult>
|
2021-06-24 09:43:57 -06:00
|
|
|
{
|
2022-06-20 09:21:08 +02:00
|
|
|
public ContentCacheDataSerializationResult(string? stringData, byte[]? byteData)
|
2021-06-24 09:43:57 -06:00
|
|
|
{
|
2022-06-20 09:21:08 +02:00
|
|
|
StringData = stringData;
|
|
|
|
|
ByteData = byteData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string? StringData { get; }
|
|
|
|
|
|
|
|
|
|
public byte[]? ByteData { get; }
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public static bool operator ==(ContentCacheDataSerializationResult left, ContentCacheDataSerializationResult right)
|
|
|
|
|
=> left.Equals(right);
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public static bool operator !=(ContentCacheDataSerializationResult left, ContentCacheDataSerializationResult right)
|
|
|
|
|
=> !(left == right);
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public override bool Equals(object? obj)
|
|
|
|
|
=> obj is ContentCacheDataSerializationResult result && Equals(result);
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
public bool Equals(ContentCacheDataSerializationResult other)
|
|
|
|
|
=> StringData == other.StringData &&
|
|
|
|
|
EqualityComparer<byte[]>.Default.Equals(ByteData, other.ByteData);
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
var hashCode = 1910544615;
|
|
|
|
|
if (StringData is not null)
|
2021-06-24 09:43:57 -06:00
|
|
|
{
|
2022-06-20 09:21:08 +02:00
|
|
|
hashCode = (hashCode * -1521134295) + EqualityComparer<string>.Default.GetHashCode(StringData);
|
2021-06-24 09:43:57 -06:00
|
|
|
}
|
|
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
if (ByteData is not null)
|
|
|
|
|
{
|
|
|
|
|
hashCode = (hashCode * -1521134295) + EqualityComparer<byte[]>.Default.GetHashCode(ByteData);
|
|
|
|
|
}
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-06-20 09:21:08 +02:00
|
|
|
return hashCode;
|
2021-06-24 09:43:57 -06:00
|
|
|
}
|
|
|
|
|
}
|