首页 > 解决方案 > C# 反射:如何搜索程序集并获取泛型类型

问题描述

对于不同的事件,我有不同的 audittrail 工厂:

DomainEventA: DomainEvent
DomainEventB: DomainEvent

...

我如何遍历每个派生的事件DomainEvent 并检查我是否有AuditTrailFactoryof T

 foreach (var type in typeof(DomainEvent).Assembly.GetTypes().Where(x => !x.IsAbstract && x.IsSubclassOf(typeof(DomainEvent))))
            {
                Assert.NotNull(AuditTrailFactoryProvider.GetAuditTrailFactory<T>());
            }

标签: c#genericsreflection

解决方案


推荐阅读