Made all models implement IEquatable<> generic, allowing for validating of equality of data.
47 lines
No EOL
1.1 KiB
C#
47 lines
No EOL
1.1 KiB
C#
using System;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Text.Json;
|
|
|
|
namespace FreeTubeSyncer.Models.DatabaseModels;
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
public class Setting : IDataModel, IEquatable<Setting>
|
|
{
|
|
#pragma warning disable CS8618
|
|
public string _id { get; set; } = string.Empty;
|
|
public string value { get; set; } = string.Empty;
|
|
|
|
public string Id() => _id;
|
|
public bool EqualId(string oid) => _id == oid;
|
|
|
|
public void MarshalData(string id, string data)
|
|
{
|
|
_id = id;
|
|
value = data;
|
|
}
|
|
|
|
public string JsonData()
|
|
{
|
|
return value;
|
|
}
|
|
|
|
public bool Equals(Setting? other)
|
|
{
|
|
if (other is null) return false;
|
|
if (ReferenceEquals(this, other)) return true;
|
|
return _id == other._id && value == other.value;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj is null) return false;
|
|
if (ReferenceEquals(this, obj)) return true;
|
|
if (obj.GetType() != GetType()) return false;
|
|
return Equals((Setting)obj);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return HashCode.Combine(_id, value);
|
|
}
|
|
} |