首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NDepend:如何从查询导出结果

NDepend:如何从查询导出结果
EN

Stack Overflow用户
提问于 2021-07-14 15:15:58
回答 1查看 37关注 0票数 1

我得到了一个CQLinq查询,它返回每个方法的方法列表和成员列表。导出查询结果将只显示元素的数量。我考虑使用Linq Aggregate( (a,b) => a + ',' + b)。有没有更好的解决办法?

代码语言:javascript
复制
let type = Application.Types.WithFullName("WPF.ViewModels.CouponViewModel").Single()
let dicoFields  =  type.Fields
   .ToDictionary(f => f, f => f.MethodsUsingMe.Where(m => m.ParentType == f.ParentType))
let dicoMethods = type.Methods
   .ToDictionary(m => m, m => m.MembersUsed.Where(f => f.ParentType == m.ParentType))

// The partition algorithm on both dicos here

//from pair in dicoFields 
//orderby   pair.Value.Count() descending
//select new { pair.Key, pair.Value } 

from pair in dicoMethods 
orderby   pair.Value.Count() descending
select new { pair.Key, pair.Value} 

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-15 07:43:05

实际上,您可以这样重写查询:

代码语言:javascript
复制
let type = Application.Types.WithFullName("WPF.ViewModels.CouponViewModel").Single()
let dicoMembers  =  type.ChildMembers
   .ToDictionary(x => x, x => 
  x.IsField ? x.AsField.MethodsUsingMe.Where(m => m.ParentType == x.ParentType):
              x.AsMethod.MembersUsed.Where(f => f.ParentType == x.ParentType))

from pair in dicoMembers
orderby   pair.Value.Count() descending
select new { 
 pair.Key, 
 str = pair.Value.Any() ?
    pair.Value.Select(x => x.Name).Aggregate( (a,b) => a + " ; " + b) :
    "empty"
} 

方法和字段都采用account

  • Methods,
  • 使用字段,方法使用的成员聚合在字符串

中。

然后,您可以导出结果:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68380745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档