Created
July 3, 2015 13:34
-
-
Save lsancho/a99f730b10a51f9d8881 to your computer and use it in GitHub Desktop.
Get All InnerException Messages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<TSource> FromHierarchy<TSource>( | |
this TSource source, | |
Func<TSource, TSource> nextItem, | |
Func<TSource, bool> canContinue) | |
{ | |
for (var current = source; canContinue(current); current = nextItem(current)) | |
{ | |
yield return current; | |
} | |
} | |
public static IEnumerable<TSource> FromHierarchy<TSource>( | |
this TSource source, | |
Func<TSource, TSource> nextItem) | |
where TSource : class | |
{ | |
return FromHierarchy(source, nextItem, s => s != null); | |
} | |
public static string GetAllMessages(this Exception exception) | |
{ | |
var messages = exception.FromHierarchy(ex => ex.InnerException) | |
.Select(ex => ex.Message); | |
return String.Join(Environment.NewLine, messages); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment