本文整理汇总了C#中System.Linq.DetectCycles方法的典型用法代码示例。如果您正苦于以下问题:C# System.Linq.DetectCycles方法的具体用法?C# System.Linq.DetectCycles怎么用?C# System.Linq.DetectCycles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq
的用法示例。
在下文中一共展示了System.Linq.DetectCycles方法的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();
}
示例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");
}