简体   繁体   English

当我使用LINQ时,为什么Class Coupling会跳转?

[英]Why does Class Coupling jump when I use LINQ?

I have a method that takes three parameters: List<Class1> source , List<Class2) results , and DateTime endDate . 我有一个方法,它有三个参数: List<Class1> sourceList<Class2) resultsDateTime endDate I can see why the class coupling is four. 我可以看出为什么类耦合是四。 However, it jumps to ten when I add this statement: 但是,当我添加此语句时,它会跳到

var warnings = from s in source
    join r in results on s.Field1 equals r.Field1 into joined
    from j in joined.DefaultIfEmpty( )
    where j == null
    select string.Format( "{0}{1}", A_CONSTANT, s.Field2 );

My questions: 我的问题:

  1. What are the six new classes that were introduced by the LINQ statement? LINQ语句引入的六个新类是什么?
  2. And since ten is the upper limit of "good code," does this indicate that LINQ is not a good choice here? 由于十是“好代码”的上限,这是否表明LINQ不是一个好选择?

The six additional classes are possibly: 另外六个类可能是:

  • IEnumerable<string> - the result of your query IEnumerable<string> - 查询的结果
  • IEnumerable<Class1> - the left collection IEnumerable<Class1> - 左集合
  • IEnumerable<Class2> - the right collection IEnumerable<Class2> - 正确的集合
  • Func<Class1, int> - the left part of the join expression Func<Class1, int> - 连接表达式的左侧部分
  • Func<Class2, int> - the right part of the join expression Func<Class2, int> - 连接表达式的右侧部分
  • Func<Class1, Class2, string> - the projection Func<Class1, Class2, string> - 投影

It's also possible that it's counting the Enumerable class since the query is translated to static extension method calls. 由于查询被转换为静态扩展方法调用,因此它也可能计算Enumerable类。

In either case, the code analysis does not seem to ignore transient classes used by Linq (whether it should or not is debatable). 在任何一种情况下,代码分析似乎都不会忽略Linq使用的瞬态类(无论它是否应该是有争议的)。 My advice is to either ignore it (perhaps manually counting the coupling and noting the difference) or finding a better analysis tool. 我的建议是要么忽略它(可能手动计算耦合并注意差异)或找到更好的分析工具。

Another question would be: does it increase your coupling overall ? 另一个问题是:它是否会增加你的整体耦合? I suspect that several of these classes are used throughout your app, so it may not make a significant difference on your overall coupling. 我怀疑在您的应用程序中使用了其中几个类,因此它可能不会对您的整体耦合产生显着影响。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我的类实现IEnumerable时,为什么不能使用LINQ to Objects <T> 多次? - Why can't I use LINQ to Objects when my class implements IEnumerable<T> multiple times? 为什么nameof()在Linq表达式中给出了一个模糊的调用警告,但是当我使用相同的值作为字符串时呢? - Why does nameof() give an ambiguous invocation warning in a Linq expression, but not when I use the same value as a string? 当我按下“跳跃”按钮时,我的播放器并不总是跳跃 - My player does not always jump when i press the "jump" button 为什么在对List进行交互时resharper不建议使用linq? - Why resharper does not suggest to use linq when interating over a List? 为什么当我有一个类时我的程序运行,而当我使用两个类时却不能运行? - Why does my program run when I have one class, but not when I use two? 为什么我不能跳还是跳得好? - Why can't I jump, or jump well? EntityFramework为什么耦合表获得重复的值? - Entityframework why does coupling table get duplicated values? 为什么在VS2017中,Visual Studio 2010不允许在linq查询中使用“is null”? - Why doesn't Visual Studio 2010 allow the use of “is null” in a linq query when VS2017 does? 为什么我不能在我的类上使用LINQ方法实现IEnumerable? - Why can't I use LINQ methods on my class implementing IEnumerable? 为什么我不能在 LINQ-to-SQL 连接方法中使用实际的 class ? - Why can't I use an actual class in LINQ-to-SQL join method?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM