如何使用CQLinq在单个查询中获取方法和字段的度量 [英] How to use CQLinq to get metrics of Methods and Fields within a single query

查看:85
本文介绍了如何使用CQLinq在单个查询中获取方法和字段的度量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用NDepend中的CQLinq计算标识符的平均长度,我想获取类,字段和方法的名称的长度.我浏览了CQlinq的以下页面: http://www.ndepend.com/docs/cqlinq-syntax ,我有类似的代码:

I am calculating average length of identifiers with CQLinq in NDepend, and I want to get the length of the names of classes, fields and methods. I walked through this page of CQlinq: http://www.ndepend.com/docs/cqlinq-syntax, and I have code like:

let id_m = Methods.Select(m => new { m.SimpleName, m.SimpleName.Length })
let id_f = Fields.Select(f => new { f.Name, f.Name.Length })
select id_m.Union(id_f)

它不起作用,一个错误提示:

It doesn't work, one error says:

"System.Collections.Generic.IEnumerable"没有 包含联盟"的定义...

'System.Collections.Generic.IEnumerable' does not contain a definition for 'Union'...

另一个是:

无法从转换 'System.Collections.Generic.IEnumerable'至 'System.Collections.Generic.HashSet'

cannot convert from 'System.Collections.Generic.IEnumerable' to 'System.Collections.Generic.HashSet'

但是,根据 MSDN ,IEnumerable接口定义了Union()和Concat()方法.

However, according to MSDN, IEnumerable Interface defines Union() and Concat() methods.

在我看来,我不能使用与Linq完全相同的方式使用CQLinq.无论如何,是否有一种方法可以从singe查询中的Types,Methods和Fields域中获取信息?

It seems to me that I cannot use CQLinq exactly the same way as Linq. Anyway, is there a way to get the information from Types, Methods and Fields domains within a singe query?

非常感谢.

推荐答案

是否有一种方法可以在单查询中从Types,Methods和Fields域中获取信息?

is there a way to get the information from Types, Methods and Fields domains within a singe query?

暂时不可以,因为CQLinq查询只能匹配类型序列,方法序列或字段序列,因此您需要3个不同的代码查询.

Not for now, because a CQLinq query can only match a sequence of types, or a sequence of methods or a sequence of field, so you need 3 distinct code queries.

对于下一个版本的CQLinq,将进行很多改进,实际上您将能够编写如下内容:

For next version CQLinq, will be improved a lot and indeed you'll be able to write things like:

from codeElement in Application.TypesAndMembers 
select new { codeElement, codeElement.Name.Length }

下一版本将在2016年底之前提供.

Next version will be available before the end of the year 2016.

这篇关于如何使用CQLinq在单个查询中获取方法和字段的度量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆