本文整理匯總了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));
}