1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Bowin.Common.Utility
- {
- public static class ExceptionHelper
- {
- public static string GetFullExceptionMessage(this Exception ex)
- {
- string message = ex.Message + "|" + ex.StackTrace;
- if (ex.InnerException != null)
- {
- message += "\n\t" + GetFullExceptionMessage(ex.InnerException);
- }
- return message;
- }
- public static IEnumerable<T> FindException<T>(this Exception ex) where T : Exception
- {
- var result = new List<T>();
- if (ex is AggregateException)
- {
- result.AddRange(((AggregateException)ex).InnerExceptions.SelectMany(x => x.FindException<T>()));
- }
- else
- {
- if (ex is T)
- {
- result.Add((T)ex);
- }
- if (ex.InnerException != null)
- {
- result.AddRange(ex.InnerException.FindException<T>());
- }
- }
- return result;
- }
- }
- }
|