C# 特性(Attribute)
1.定义特性类
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = false)] public class MQDtoAttribute:Attribute { public string Topic { get; set; } public bool IsClient { get; set; } = false; public MQDtoAttribute(string topic) { this.Topic = topic; } public MQDtoAttribute(string topic,bool isClient) { this.Topic = topic; this.IsClient = isClient; } }
2.使用特性类
[MQDto("/sys/post", isClient: true)] public class EquipmentEventReport { /// <summary> /// /// </summary> public string id { get; set; } }

浙公网安备 33010602011771号