MessageHandlerAttribute.cs 519 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. namespace Model
  4. {
  5. /// <summary>
  6. /// 搭配MessageComponent用来分发消息
  7. /// </summary>
  8. public class MessageHandlerAttribute : Attribute
  9. {
  10. private HashSet<AppType> AppTypes { get; } = new HashSet<AppType>();
  11. public MessageHandlerAttribute(params AppType[] appTypes)
  12. {
  13. foreach (AppType appType in appTypes)
  14. {
  15. this.AppTypes.Add(appType);
  16. }
  17. }
  18. public bool Contains(AppType appType)
  19. {
  20. return this.AppTypes.Contains(appType);
  21. }
  22. }
  23. }