c# - C# 反射:如何搜索程序集并获取泛型类型
问题描述
对于不同的事件,我有不同的 audittrail 工厂:
DomainEventA: DomainEvent
DomainEventB: DomainEvent
...
我如何遍历每个派生的事件DomainEvent
并检查我是否有AuditTrailFactory
of T
?
foreach (var type in typeof(DomainEvent).Assembly.GetTypes().Where(x => !x.IsAbstract && x.IsSubclassOf(typeof(DomainEvent))))
{
Assert.NotNull(AuditTrailFactoryProvider.GetAuditTrailFactory<T>());
}
解决方案
推荐阅读
- javascript - copyTpl 完成后如何执行代码?
- firebase - 始终将 event.data 接收为 null,推送事件服务人员
- ruby-on-rails - rails 如何知道它是否在子路径下运行?
- amazon-web-services - 发送带有嵌入图像的 AWS SES 电子邮件不起作用?
- python - 如何比较Python中的列表元素
- sql - Redshift - 查找特定 ID 的标志出现的次数
- c# - C# LINQ 行为
- ssl - 启用本地 SSL 证书后量角器测试失败
- c++ - 命名空间中有 2 个同名的类
- oracle - 在某些数字之后开始匹配过程的 Oracle 联接表