在 NDepend 中构建 CQL 以验证 MVVM 模式
我想通过静态分析来验证 C# 代码中的一些设计模式。我想使用 NDepend 验证这些。该应用程序是使用 MVVM 设计风格构建的,因此我想验证的典型设计模式是: 1. View-Model 类没有任何 DependencyProperties(WPF 元素),它们只能在 View 层中看到。 2.视图层不应该实现IDisposable等
我尝试在CQL中构建查询来捕获这些细节,但失败了,因为我需要验证类属于哪个级别以及它的属性。我了解 CQL 尚不支持嵌套查询,那么有什么方法可以通过 NDepend 捕获这些详细信息?我希望我能以某种方式捕获多个查询的结果并执行它们的交集?
提前致谢, 肖恩
I wanted to verify few design patterns in C# code by static analysis. I want to verify these using NDepend. The application is built with MVVM design style, so typical design patterns that I would like to verify are:
1. View-Model classes do not have any DependencyProperties (WPF elements), they should only be seen in View layer.
2. The View layer should not implement IDisposable etc
I have tried building queries in CQL to capture these details, but failed as I need to verify which level a class belongs to and also the properties of it. I understand nested query is not supported by CQL yet, so is there any way I can capture these details by NDepend? I am hoping I can somehow capture the results of multiple queries and perform intersection of them?
Thanks in advance,
Shaun
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获取 CQLinq 规则 的最简单方法,该规则会警告 A 是否正在使用 B(A 和B 可以是程序集/命名空间/类型/方法/字段)是为了查看依赖关系矩阵中的A和B,并生成一个代码规则,警告是否存在此依赖关系 :
...结果,生成以下规则:
< img src="https://i.sstatic.net/QFNgI.png" alt="生成的代码规则">
The easiest way to get a CQLinq rule that warns if A is using B (A and B can be Assembly/ Namespace/ Type/ Method/ Field) is to view A and B in the Dependency Matrix, and to Generate a code rule that warns if this dependency exists:
...and as a result, the following rule is generated: