本文整理汇总了C#中System.AggregateException.FlattenInnerExceptions方法的典型用法代码示例。如果您正苦于以下问题:C# AggregateException.FlattenInnerExceptions方法的具体用法?C# AggregateException.FlattenInnerExceptions怎么用?C# AggregateException.FlattenInnerExceptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.AggregateException
的用法示例。
在下文中一共展示了AggregateException.FlattenInnerExceptions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_flatten_aggregate_exceptions
public void Should_flatten_aggregate_exceptions()
{
var exception1 = new Exception("Exception 1", new Exception("Inner exception of exception 1"));
var exception2 = new Exception("Exception 2", new Exception("Inner exception of exception 2"));
var exception3 = new Exception("Exception 3", new Exception("Inner exception of exception 3"));
// Aggregate exceptions nested three levels deep.
var aggregate3 = new AggregateException(exception3);
var aggregate2 = new AggregateException(aggregate3, exception2);
var aggregate1 = new AggregateException(aggregate2, exception1);
var result = aggregate1.FlattenInnerExceptions();
Assert.IsType<AggregateException>(result);
// Only the inner exceptions of any aggregates should be returned. The inner exception
// of a non-aggregate should not be flattened.
var innerExceptions = ((AggregateException)result).InnerExceptions;
var expectedExceptions = new[] { exception1, exception2, exception3 };
Assert.Equal(3, innerExceptions.Count);
foreach (var exception in expectedExceptions)
Assert.True(innerExceptions.Contains(exception));
}