34 lines
1.2 KiB
C#
34 lines
1.2 KiB
C#
|
using System.Diagnostics.CodeAnalysis;
|
||
|
using SQLite;
|
||
|
|
||
|
namespace Innovenergy.Backend.Model.Relations;
|
||
|
|
||
|
public abstract class Relation<L,R>
|
||
|
{
|
||
|
[PrimaryKey, AutoIncrement]
|
||
|
[Obsolete("Do not use for any business logic")]
|
||
|
public Int64 Id { get; set; }
|
||
|
|
||
|
[Ignore] protected L Left { get; set; } = default!;
|
||
|
[Ignore] protected R Right { get; set; } = default!;
|
||
|
|
||
|
protected Boolean Equals(Relation<L, R> other)
|
||
|
{
|
||
|
return EqualityComparer<L>.Default.Equals(Left, other.Left)
|
||
|
&& EqualityComparer<R>.Default.Equals(Right, other.Right);
|
||
|
}
|
||
|
|
||
|
public override Boolean Equals(Object? obj)
|
||
|
{
|
||
|
if (ReferenceEquals(null, obj)) return false;
|
||
|
if (ReferenceEquals(this, obj)) return true;
|
||
|
|
||
|
return obj.GetType() == GetType() && Equals((Relation<L, R>)obj);
|
||
|
}
|
||
|
|
||
|
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")]
|
||
|
public override Int32 GetHashCode() => HashCode.Combine(Left, Right);
|
||
|
|
||
|
public static Boolean operator ==(Relation<L, R>? left, Relation<L, R>? right) => Equals(left, right);
|
||
|
public static Boolean operator !=(Relation<L, R>? left, Relation<L, R>? right) => !Equals(left, right);
|
||
|
}
|