我想定义一个扩展方法,它会递归到嵌套结构中,你猜对了,异常。这就是我想要做的......
class Utils
{
public static string TellMeEverything(this Exception ex)
{
return ex.InnerException?.TellMeEverything() + ex.Message + ex.StackTrace;
}
}
但这会产生编译器错误'Exception' does not contain a definition for 'TellMeEverything' and no extension method 'TellMeEverything' accepting a first argument of type 'Exception' could be found (are you missing a using directive or an assembly reference?)
这可能被视为编译器错误吗?
答案 0 :(得分:5)
您的class utils
也应为public static
,以便将其作为System.Exception