61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using System;
|
|
|
|
namespace SLSUtilities.General
|
|
{
|
|
/// <summary>
|
|
/// 实现该接口的类可以根据优先级进行比较和排序。
|
|
/// 数字越大优先级越高。
|
|
/// </summary>
|
|
public interface IPrioritized : IComparable<IPrioritized>
|
|
{
|
|
int Priority { get; }
|
|
|
|
int IComparable<IPrioritized>.CompareTo(IPrioritized other)
|
|
{
|
|
return other.Priority.CompareTo(Priority);
|
|
}
|
|
}
|
|
|
|
public static class IPrioritizedExtensions
|
|
{
|
|
public static PrioritizedAction ToPrioritized<T>(this Action action, int priority = 0)
|
|
{
|
|
return new PrioritizedAction(action, priority);
|
|
}
|
|
|
|
public static PrioritizedAction<T> ToPrioritized<T>(this Action<T> action, int priority = 0)
|
|
{
|
|
return new PrioritizedAction<T>(action, priority);
|
|
}
|
|
|
|
public static PrioritizedAction<T1, T2> ToPrioritized<T1, T2>(this Action<T1, T2> action, int priority = 0)
|
|
{
|
|
return new PrioritizedAction<T1, T2>(action, priority);
|
|
}
|
|
|
|
public static PrioritizedAction<T1, T2, T3> ToPrioritized<T1, T2, T3>(this Action<T1, T2, T3> action, int priority = 0)
|
|
{
|
|
return new PrioritizedAction<T1, T2, T3>(action, priority);
|
|
}
|
|
|
|
public static PrioritizedFunc<TR> ToPrioritized<TR>(this Func<TR> func, int priority = 0)
|
|
{
|
|
return new PrioritizedFunc<TR>(func, priority);
|
|
}
|
|
|
|
public static PrioritizedFunc<T, TR> ToPrioritized<T, TR>(this Func<T, TR> func, int priority = 0)
|
|
{
|
|
return new PrioritizedFunc<T, TR>(func, priority);
|
|
}
|
|
|
|
public static PrioritizedFunc<T1, T2, TR> ToPrioritized<T1, T2, TR>(this Func<T1, T2, TR> func, int priority = 0)
|
|
{
|
|
return new PrioritizedFunc<T1, T2, TR>(func, priority);
|
|
}
|
|
|
|
public static PrioritizedFunc<T1, T2, T3, TR> ToPrioritized<T1, T2, T3, TR>(this Func<T1, T2, T3, TR> func, int priority = 0)
|
|
{
|
|
return new PrioritizedFunc<T1, T2, T3, TR>(func, priority);
|
|
}
|
|
}
|
|
} |