using System; namespace SepCore.Timer { /// /// 定时任务句柄。 /// public readonly struct TimerHandle : IEquatable { public static readonly TimerHandle Invalid = new TimerHandle(0); public TimerHandle(int id) { Id = id; } /// /// 获取定时任务编号。 /// public int Id { get; } /// /// 获取句柄是否有效。 /// public bool IsValid => Id > 0; public bool Equals(TimerHandle other) { return Id == other.Id; } public override bool Equals(object obj) { return obj is TimerHandle other && Equals(other); } public override int GetHashCode() { return Id; } public static bool operator ==(TimerHandle left, TimerHandle right) { return left.Equals(right); } public static bool operator !=(TimerHandle left, TimerHandle right) { return !left.Equals(right); } } }