This commit is contained in:
2020-09-27 22:16:57 +02:00
parent 1811ea5a1a
commit 5c86727baa
9 changed files with 55 additions and 11 deletions

View File

@ -5,12 +5,12 @@ using System.ComponentModel.DataAnnotations;
namespace UserService.Infrastructure.DataModels
{
public abstract class Node : ICloneable
public abstract class Node : ICloneable, IComparable<Node>
{
public Guid Id { get; set; }
[Required] public string CommonName { get; set; } = null!;
public string? Description { get; set; }
public ICollection<Node> Children { get; set; } = new List<Node>();
public ISet<Node> Children { get; set; } = new SortedSet<Node>();
public Node? Parent { get; set; } //Parent
public Guid? ParentId { get; set; }
@ -20,5 +20,14 @@ namespace UserService.Infrastructure.DataModels
/// <inheritdoc />
public virtual object Clone() => MemberwiseClone();
public int CompareTo(Node? other)
{
if (ReferenceEquals(this, other)) return 0;
if (ReferenceEquals(null, other)) return 1;
var commonNameComparison = string.Compare(CommonName, other.CommonName, StringComparison.Ordinal);
if (commonNameComparison != 0) return commonNameComparison;
return Id.CompareTo(other.Id);
}
}
}