Innovenergy_trunk/csharp/App/Backend/Model/Relations/Relation.cs

34 lines
1.2 KiB
C#
Raw Normal View History

2023-02-16 12:57:06 +00:00
using System.Diagnostics.CodeAnalysis;
using SQLite;
2023-02-24 11:58:47 +00:00
namespace Innovenergy.Backend.Model.Relations;
2023-02-16 12:57:06 +00:00
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);
}