CommunicationAttribute.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. namespace TeamAAS.Communication.Attributes
  3. {
  4. /// <summary>
  5. /// 通讯设备特性标记。实现 ICommunication 的设备类必须标记本特性,
  6. /// 反射加载时会根据 DisplayName 生成下拉选项,按 Category 分组。
  7. /// 新增设备只需:实现 ICommunication + 加本特性,无需改动任何现有代码。
  8. /// </summary>
  9. [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
  10. public sealed class CommunicationAttribute : Attribute
  11. {
  12. /// <summary>显示名称,如"三菱 PLC"</summary>
  13. public string DisplayName { get; }
  14. /// <summary>分类,如"PLC"、"仪器",用于下拉框分组,默认 PLC</summary>
  15. public string Category { get; }
  16. /// <summary>说明</summary>
  17. public string Description { get; }
  18. /// <summary>
  19. /// 品牌专属调试页类型(必须是 <c>System.Windows.FrameworkElement</c> 的子类,且建议实现
  20. /// <c>TeamAAS.Communication.UI.ICommunicationDebugPage</c> 以接收通讯设备实例)。
  21. /// 为 null(默认)时,宿主使用通用的通讯测试面板。
  22. /// 用法:[Communication("三菱 PLC", "PLC", DebugPageType = typeof(MitsubishiDebugPage))]
  23. /// </summary>
  24. public Type DebugPageType { get; set; }
  25. public CommunicationAttribute(string displayName, string category = "PLC", string description = "")
  26. {
  27. DisplayName = displayName;
  28. Category = category;
  29. Description = description;
  30. }
  31. }
  32. }