2021-06-24 09:43:57 -06:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Cms.Infrastructure.PublishedCache.DataSource
|
|
|
|
|
{
|
|
|
|
|
/// <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>
|
|
|
|
|
{
|
2022-03-30 13:34:56 +02:00
|
|
|
public ContentCacheDataSerializationResult(string? stringData, byte[]? byteData)
|
2021-06-24 09:43:57 -06:00
|
|
|
{
|
|
|
|
|
StringData = stringData;
|
|
|
|
|
ByteData = byteData;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 13:34:56 +02:00
|
|
|
public string? StringData { get; }
|
|
|
|
|
public byte[]? ByteData { get; }
|
2021-06-24 09:43:57 -06:00
|
|
|
|
2022-03-30 13:34:56 +02:00
|
|
|
public override bool Equals(object? obj)
|
2021-06-24 09:43:57 -06:00
|
|
|
=> obj is ContentCacheDataSerializationResult result && Equals(result);
|
|
|
|
|
|
|
|
|
|
public bool Equals(ContentCacheDataSerializationResult other)
|
|
|
|
|
=> StringData == other.StringData &&
|
|
|
|
|
EqualityComparer<byte[]>.Default.Equals(ByteData, other.ByteData);
|
|
|
|
|
|
|
|
|
|
public override int GetHashCode()
|
|
|
|
|
{
|
|
|
|
|
var hashCode = 1910544615;
|
2022-03-30 13:34:56 +02:00
|
|
|
if (StringData is not null)
|
|
|
|
|
{
|
|
|
|
|
hashCode = hashCode * -1521134295 + EqualityComparer<string>.Default.GetHashCode(StringData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ByteData is not null)
|
|
|
|
|
{
|
|
|
|
|
hashCode = hashCode * -1521134295 + EqualityComparer<byte[]>.Default.GetHashCode(ByteData);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-24 09:43:57 -06:00
|
|
|
return hashCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool operator ==(ContentCacheDataSerializationResult left, ContentCacheDataSerializationResult right)
|
|
|
|
|
=> left.Equals(right);
|
|
|
|
|
|
|
|
|
|
public static bool operator !=(ContentCacheDataSerializationResult left, ContentCacheDataSerializationResult right)
|
|
|
|
|
=> !(left == right);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|