Có cách nào để viết mã kiểu LINQ "tay ngắn" để đi đến tất cả các cấp của (các) bên trong của Ngoại lệ được ném ra không? Tôi muốn viết nó tại chỗ thay vì gọi một hàm mở rộng (như bên dưới) hoặc kế thừa Exceptionlớp.
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;
}
};