微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 CQLinq 中分组?

如何解决如何在 CQLinq 中分组?

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

我想弄清楚哪些没有被使用。这是我目前拥有的 CQLinq:

// 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 } 

唉,这行不通。错误信息是:

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 个项目的条目。但看起来我的计划行不通,因为不支持分组。

你会怎么做?

解决方法

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

// 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 }

我想知道如何简化。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?