當前位置: 首頁>>代碼示例>>C#>>正文


C# AggregateException.FlattenInnerExceptions方法代碼示例

本文整理匯總了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));
        }
開發者ID:RadifMasud,項目名稱:Nancy,代碼行數:25,代碼來源:ExceptionExtensionsFixture.cs


注:本文中的System.AggregateException.FlattenInnerExceptions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。