36 lines
992 B
C#
36 lines
992 B
C#
using System;
|
|
|
|
namespace Cryville.Common {
|
|
public struct Identifier : IEquatable<Identifier> {
|
|
public static Identifier Empty = new Identifier(0);
|
|
public int Key { get; private set; }
|
|
public object Name { get { return IdentifierManager.SharedInstance.Retrieve(Key); } }
|
|
public Identifier(int key) {
|
|
Key = key;
|
|
}
|
|
public Identifier(object name) {
|
|
Key = IdentifierManager.SharedInstance.Request(name);
|
|
}
|
|
public override bool Equals(object obj) {
|
|
if (obj == null || !(obj is Identifier)) return false;
|
|
return Equals((Identifier)obj);
|
|
}
|
|
public bool Equals(Identifier other) {
|
|
return Key == other.Key;
|
|
}
|
|
public override int GetHashCode() {
|
|
return Key;
|
|
}
|
|
public override 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);
|
|
}
|
|
}
|
|
}
|