Skip to content

Instantly share code, notes, and snippets.

@lsancho
Created July 3, 2015 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsancho/a99f730b10a51f9d8881 to your computer and use it in GitHub Desktop.
Save lsancho/a99f730b10a51f9d8881 to your computer and use it in GitHub Desktop.
Get All InnerException Messages
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