มีวิธีใดในการเขียนโค้ด "มือสั้น" สไตล์ LINQ สำหรับการเดินไปยังทุกระดับของ InnerException (s) ของ Exception ที่ถูกโยน? ฉันอยากจะเขียนแทนการเรียกฟังก์ชันส่วนขยาย (ตามด้านล่าง) หรือสืบทอด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;
}
};