首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在CQLinq中分组?

如何在CQLinq中分组?
EN

Stack Overflow用户
提问于 2021-01-24 02:44:46
回答 1查看 42关注 0票数 2

我有一个自动生成的接口和实现,它们定义了3000+方法,并为每个方法定义了各自的异步签名。总而言之,6,000+方法。

我想找出哪些没有用过。这是我到目前为止拥有的CQLinq:

代码语言:javascript
复制
// Unused methods in the interface
let notUsed1 = new HashSet<IMethod>( 
from t in JustMyCode.Types 
where t.Name == "IDataProcessor"
from m in t.Methods 
where !m.HasAttribute("xyz.CoreService.CoreServiceOperationAttribute") &&  !m.MethodsCallingMe.Any()
select m)
// Unused methods in the concrete implementation of the interface
let notUsed2 =
from t in JustMyCode.Types 
where t.Name == "DataProcessor"
from m in t.Methods 
where m.HasAttribute("System.CodeDom.Compiler.GeneratedCodeAttribute") && !m.MethodsCallingMe.Any()
// Obtain the methods in the intersection
select m
from m in notUsed2 where notUsed1.Contains(m.OverriddensBase.Single())
let baseName = m.SimpleName.Replace("Async", "")
group m by baseName into g
select new { g } 

可惜,这是行不通的。错误消息为:

代码语言:javascript
复制
Ln 18  Col 8  Type {IGrouping`2<String,IMethod>} not accepted to type first result argument.
Only IMethod, IField, IType, INamespace, IAssembly, IMember, ICodeElement, ICodeElementParent, ICodeContainer, IIssue and IRule are accepted to type first result argument.

看起来group是不可能的。我的想法是按基本名称对方法进行分组(对于同步和异步签名,这是相同的),并选择具有2个项的条目。但看起来我的计划不会起作用,因为不支持分组。

你会怎么做?

EN

回答 1

Stack Overflow用户

发布于 2021-01-24 02:59:34

我设法通过将分组键更改为IMethod对象来解决此问题:

代码语言:javascript
复制
// Collect the sync methods
let syncMethods = (
from t in JustMyCode.Types 
where t.Name == "IDataProcessor"
from m in t.Methods 
where !m.HasAttribute("xyz.CoreService.CoreServiceOperationAttribute") && !m.IsAsync
select m).ToDictionary(m => m.SimpleName)
// Unused methods in the interface
let notUsed1 = new HashSet<IMethod>( 
from t in JustMyCode.Types 
where t.Name == "IDataProcessor"
from m in t.Methods 
where !m.HasAttribute("xyz.CoreService.CoreServiceOperationAttribute") && !m.MethodsCallingMe.Any()
select m)
// Unused methods in the concrete implementation of the interface
let notUsed2 =
from t in JustMyCode.Types 
where t.Name == "DataProcessor"
from m in t.Methods 
where m.HasAttribute("System.CodeDom.Compiler.GeneratedCodeAttribute") && !m.MethodsCallingMe.Any()
// Select methods in the intersection
select m
from m in notUsed2 where notUsed1.Contains(m.OverriddensBase.Single())
let syncMethod = syncMethods[m.SimpleName.Replace("Async", "")]
group m by syncMethod into g     // group by the respective sync method
where g.Count() == 2     // return if both sync and async signatures are not used
select new { g.Key }

我想知道如何才能简化这一点。

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

https://stackoverflow.com/questions/65863089

复制
相关文章

相似问题

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