【发布时间】:2011-10-12 09:34:50
【问题描述】:
Public interface IRuleObject {}
Public class RuleBase : IRuleObject {}
Public class Length : RuleBase {}
Public class Range : RuleBase {}
Public class SetDefault : IRuleObject {}
我正在尝试编写一段代码,我可以在其中获取所有实现的类 IRuleObject...
正如您所注意到的,一些 Rules 可能源自实现 IRuleObject 的 RuleBase,还有一些其他的 Rules 不继承 RuleBase 并尝试自行实现 IRuleObject。上述所有规则都可以分配给IRuleObject。
我试过了:
Assembly dll = Assembly.GetAssembly(typeof(IRuleObject));
var rules = dll.GetTypes().Where(x => x.IsAssignableFrom(typeof(IRuleObject)));
但它无法检索 规则
想法表示赞赏:-)
谢谢
【问题讨论】:
标签: c# inheritance reflection interface implementation