vampire-like/Assets/Plugins/TimerModule/Runtime/TimerHandle.cs

56 lines
1.2 KiB
C#

using System;
namespace SepCore.Timer
{
/// <summary>
/// 定时任务句柄。
/// </summary>
public readonly struct TimerHandle : IEquatable<TimerHandle>
{
public static readonly TimerHandle Invalid = new TimerHandle(0);
public TimerHandle(int id)
{
Id = id;
}
/// <summary>
/// 获取定时任务编号。
/// </summary>
public int Id
{
get;
}
/// <summary>
/// 获取句柄是否有效。
/// </summary>
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);
}
}
}