66 lines
1.6 KiB
C#
Executable File
66 lines
1.6 KiB
C#
Executable File
using System;
|
|
|
|
namespace Opsoft.NetCore.O3App.Domain
|
|
{
|
|
public abstract class EntityInt64 : Entity, IEntity<Int64>
|
|
{
|
|
public long Id { get; set; }
|
|
|
|
public override bool Equals(object obj)
|
|
{
|
|
return Equals(obj as EntityInt64);
|
|
}
|
|
|
|
private static bool IsTransient(EntityInt64 obj)
|
|
{
|
|
return obj != null && Equals(obj.Id, default(long));
|
|
}
|
|
|
|
private Type GetUnproxiedType()
|
|
{
|
|
return GetType();
|
|
}
|
|
|
|
public virtual bool Equals(EntityInt64 other)
|
|
{
|
|
if (other == null)
|
|
return false;
|
|
|
|
if (ReferenceEquals(this, other))
|
|
return true;
|
|
|
|
if (!IsTransient(this) &&
|
|
!IsTransient(other) &&
|
|
Equals(Id, other.Id))
|
|
{
|
|
var otherType = other.GetUnproxiedType();
|
|
var thisType = GetUnproxiedType();
|
|
return thisType.IsAssignableFrom(otherType) ||
|
|
otherType.IsAssignableFrom(thisType);
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
if (Equals(Id, default(long)))
|
|
{
|
|
return base.GetHashCode();
|
|
}
|
|
|
|
return Id.GetHashCode();
|
|
}
|
|
|
|
public static bool operator ==(EntityInt64 x, EntityInt64 y)
|
|
{
|
|
return Equals(x, y);
|
|
}
|
|
|
|
public static bool operator !=(EntityInt64 x, EntityInt64 y)
|
|
{
|
|
return !(x == y);
|
|
}
|
|
}
|
|
}
|