55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using System;
|
|
|
|
namespace ShrinkEventBus
|
|
{
|
|
public enum ShrinkSubscriberLifetime
|
|
{
|
|
Manual = 0,
|
|
AwakeToDestroy = 1
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
|
public sealed class ShrinkEventSubscriberAttribute : Attribute
|
|
{
|
|
public string OwnerId { get; set; } = string.Empty;
|
|
public string DefaultBus { get; set; } = string.Empty;
|
|
public ShrinkSubscriberLifetime Lifetime { get; set; } = ShrinkSubscriberLifetime.Manual;
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
|
|
public sealed class ShrinkSubscribeAttribute : Attribute
|
|
{
|
|
public string Bus { get; set; } = string.Empty;
|
|
public ShrinkEventPriority Priority { get; set; } = ShrinkEventPriority.Normal;
|
|
public int NumericPriority { get; set; }
|
|
public bool ReceiveCanceled { get; set; }
|
|
|
|
public ShrinkSubscribeAttribute() { }
|
|
|
|
public ShrinkSubscribeAttribute(ShrinkEventPriority priority, bool receiveCanceled = false)
|
|
{
|
|
Priority = priority;
|
|
ReceiveCanceled = receiveCanceled;
|
|
}
|
|
|
|
public ShrinkSubscribeAttribute(int priority)
|
|
{
|
|
NumericPriority = priority;
|
|
Priority = priority switch
|
|
{
|
|
>= 100 => ShrinkEventPriority.Highest,
|
|
>= 50 => ShrinkEventPriority.High,
|
|
>= 0 => ShrinkEventPriority.Normal,
|
|
>= -50 => ShrinkEventPriority.Low,
|
|
_ => ShrinkEventPriority.Lowest
|
|
};
|
|
}
|
|
}
|
|
|
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)]
|
|
public sealed class ShrinkEventAttribute : Attribute
|
|
{
|
|
public ShrinkDispatchMode Dispatch { get; set; } = ShrinkDispatchMode.Ordered;
|
|
}
|
|
}
|