How to use CQLinq to get metrics of Methods and Fields within a single query

社会主义新天地 提交于 2019-12-10 22:30:56

问题


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' does not contain a definition for 'Union'...

The other one is:

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

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

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?

Thanks a lot.


回答1:


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

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.

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 }

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



来源:https://stackoverflow.com/questions/37083906/how-to-use-cqlinq-to-get-metrics-of-methods-and-fields-within-a-single-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!