using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.CollectBus.Protocol.Contracts
{
public class ProtocolConstExtensions
{
///
/// 自动获取 ProtocolConst 类中所有 Kafka 主题名称
/// (通过反射筛选 public const string 且字段名以 "EventName" 结尾的常量)
///
public static List GetAllTopicNames()
{
return typeof(ProtocolConst)
.GetFields(BindingFlags.Public | BindingFlags.Static)
.Where(f =>
f.IsLiteral &&
!f.IsInitOnly &&
f.FieldType == typeof(string) &&
f.Name.EndsWith("EventName")) // 通过命名规则过滤主题字段
.Select(f => (string)f.GetRawConstantValue()!)
.ToList();
}
}
}