FxCop TypeNode.IsDerivedFrom 方法对于来自不同程序集的类型意外工作
我在程序集“A”中有基本类型“Base”,在程序集“B”中有派生类型“Child”。
我正在使用 FxCop 在程序集“B”中查找从“Base”派生的类型,如下所示:
var baseAssemblyNode = AssemblyNode.GetAssembly("A.dll"), true, true, false);
var baseType = baseAssemblyNode.Types.Single(t => t.Name.Name == "Base");
var assemblyNode = AssemblyNode.GetAssembly("B.dll"), true, true, false);
var derivedTypes = assemblyNode.Types.Where(t => t.IsDerivedFrom(baseType));
但结果集合为空。
我手动找到类型“Child”,发现它的基本类型不等于找到的“Base”类型。
这是预料之中的,因为这些类型节点是不同的对象,但在 Name 属性中具有深度 它们具有相同的 UniqueKey 和 Name - 我期望 FxCop 通过这些属性对 IsDerivedMethod 中的类型执行比较。但这不起作用。
解决这个问题有哪些选择?
I have base type "Base" in assembly "A" and derived type "Child" in assembly "B".
I'm using FxCop to find in assembly "B" types derived from "Base" like this:
var baseAssemblyNode = AssemblyNode.GetAssembly("A.dll"), true, true, false);
var baseType = baseAssemblyNode.Types.Single(t => t.Name.Name == "Base");
var assemblyNode = AssemblyNode.GetAssembly("B.dll"), true, true, false);
var derivedTypes = assemblyNode.Types.Where(t => t.IsDerivedFrom(baseType));
But the result collection is empty.
I found type "Child" manually and saw that it's base type is not equal to found "Base" type.
It was expected cause these type nodes are different objects, but in depth in Name property
they have equal UniqueKey and Name - I expected that FxCop performs comparison for types in IsDerivedMethod by these properties. But it doesn't work.
What are the options to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果类型通过引用相关,这应该可以解决问题:
这就是我用来查找从 System.Windows.Forms.Control 继承的所有类,然后确保将某些属性设置为
InitializeComponent()
。If the types are related by a reference this should do the trick:
This is what I am using to find all classes that inherit from System.Windows.Forms.Control and then ensure certain properties are being set to the team standards in the
InitializeComponent()
.