feat: added IIdentifiable comparison interface & IsIdentical extension method
This commit is contained in:
@@ -3,7 +3,7 @@ namespace Engine.Core;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents any instance in the engine with an id.
|
/// Represents any instance in the engine with an id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IIdentifiable
|
public interface IIdentifiable : System.IComparable<IIdentifiable>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event triggered when the <see cref="Id"/> of the <see cref="IIdentifiable"/> changes.
|
/// Event triggered when the <see cref="Id"/> of the <see cref="IIdentifiable"/> changes.
|
||||||
|
|||||||
@@ -101,4 +101,6 @@ public abstract class BaseEntity : IEntity
|
|||||||
|
|
||||||
protected BaseEntity() => Id = Guid.NewGuid().ToString("D");
|
protected BaseEntity() => Id = Guid.NewGuid().ToString("D");
|
||||||
protected BaseEntity(string id) => Id = id;
|
protected BaseEntity(string id) => Id = id;
|
||||||
|
|
||||||
|
public int CompareTo(IIdentifiable? other) => Id.CompareTo(other?.Id);
|
||||||
}
|
}
|
||||||
|
|||||||
7
Engine.Core/Extensions/IdentifiableExtensions.cs
Normal file
7
Engine.Core/Extensions/IdentifiableExtensions.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Engine.Core;
|
||||||
|
|
||||||
|
public static class IdentifiableExtensions
|
||||||
|
{
|
||||||
|
public static bool IsIdentical(this IIdentifiable? left, IIdentifiable? right)
|
||||||
|
=> left?.CompareTo(right) == 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user