当前位置: 首页>>代码示例>>C#>>正文


C# System.Linq.ToLookup方法代码示例

本文整理汇总了C#中System.Linq.ToLookup方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.ToLookup方法的具体用法?C# System.Linq.ToLookup怎么用?C# System.Linq.ToLookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Linq的用法示例。


在下文中一共展示了System.Linq.ToLookup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MergeCycleWithoutMergeThrows

 public void MergeCycleWithoutMergeThrows()
 {
     TestValue<string> vD;
       var graph = new[]
           {
             TestValue.Create("A", "B"),
             TestValue.Create("B", "C"),
             TestValue.Create("C", "A", "D"),
             vD = TestValue.Create("D"),
           };
       var byValue = graph.ToLookup(t => t.Value);
       var components = graph.DetectCycles(s => s.DependsOn.SelectMany(d => byValue[d]));
       Assert.AreNotEqual(components.Cycles().Count(), 0);
       var flattened = components.MergeCyclicDependencies().ToList();
 }
开发者ID:RobertGiesecke,项目名称:CycleDetection,代码行数:15,代码来源:DependencyCycleMergerTests.cs

示例2: MergeCycleWithMergeDoesNotThrows

        public void MergeCycleWithMergeDoesNotThrows()
        {
            var graph = new[]
                  {
                    TestValue.Create("A", "B"),
                    TestValue.Create("B", "C"),
                    TestValue.Create("C", "A", "D"),
                    TestValue.Create("D"),
                    TestValue.Create("E", "B", "X"),
                    TestValue.Create("X")
                  };

              var byValue = graph.ToLookup(t => t.Value);
              var components = graph.DetectCycles(s => s.DependsOn.SelectMany(d => byValue[d]));

              Assert.AreNotEqual(components.Cycles().Count(), 0);

              var flattened = components.MergeCyclicDependencies
            ((cycle, getFlattened) =>
              // create a new TestValue<> by joining all cyclic values & dependencies
             TestValue.Create
               (Join
              ("-",
               from v in cycle.Contents
               orderby v.Value
               select v.Value),
            (from t in cycle.Dependencies
             let merged = getFlattened(t)
             select merged != null
                      ? merged.Value
                      : t.Contents.Single().Value).ToArray())).ToList();

              Assert.AreEqual("D", flattened[0].Value);
              Assert.AreEqual("A-B-C", flattened[1].Value);
              Assert.AreEqual("X", flattened[2].Value);
              Assert.AreEqual("E", flattened[3].Value);

              Assert.IsTrue(flattened[1].DependsOn.Contains("D"), "A-B-C should have D as dependency");

              Assert.IsTrue(flattened[3].DependsOn.Contains("A-B-C"), "E should have A-B-C as dependency");
              Assert.IsTrue(flattened[3].DependsOn.Contains("X"), "E should have X as dependency");
        }
开发者ID:RobertGiesecke,项目名称:CycleDetection,代码行数:42,代码来源:DependencyCycleMergerTests.cs


注:本文中的System.Linq.ToLookup方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。