スローされた例外のInnerExceptionのすべてのレベルに移動するためのLINQスタイルの「ショートハンド」コードを作成する方法はありますか?拡張関数(以下のように)を呼び出したり、Exceptionクラスを継承したりするのではなく、その場で記述したいと思います。
static class Extensions
{
public static string GetaAllMessages(this Exception exp)
{
string message = string.Empty;
Exception innerException = exp;
do
{
message = message + (string.IsNullOrEmpty(innerException.Message) ? string.Empty : innerException.Message);
innerException = innerException.InnerException;
}
while (innerException != null);
return message;
}
};