Files
crtr/Assets/Cryville/Common/Identifier.cs

36 lines
991 B
C#

using System;
namespace Cryville.Common {
public struct Identifier : IEquatable<Identifier> {
public static Identifier Empty = new(0);
public int Key { get; private set; }
public readonly object Name => IdentifierManager.Shared.Retrieve(Key);
public Identifier(int key) {
Key = key;
}
public Identifier(object name) {
Key = IdentifierManager.Shared.Request(name);
}
public override readonly bool Equals(object obj) {
if (obj == null || obj is not Identifier other) return false;
return Equals(other);
}
public readonly bool Equals(Identifier other) {
return Key == other.Key;
}
public override readonly int GetHashCode() {
return Key;
}
public override readonly string ToString() {
if (Key == 0) return "";
return Name.ToString();
}
public static bool operator ==(Identifier lhs, Identifier rhs) {
return lhs.Equals(rhs);
}
public static bool operator !=(Identifier lhs, Identifier rhs) {
return !lhs.Equals(rhs);
}
}
}