更一般地说,我想知道当要参数化的类型的目标不是顶级属性时,您如何制作通用例程。
具体来说,我正在努力消除这两个函数的重复:
private static string ExceptionMessage(Exception e)
{
string result = string.Empty;
Exception exception = e;
while (exception != null)
{
if (e.Message != null)
{
if (result.Length > 0)
{
result += Separator;
}
result += exception.Message;
}
exception = exception.InnerException;
}
return result;
}
private static string Tag(Exception e)
{
string result = string.Empty;
Exception exception = e;
while (exception != null)
{
if (e.TargetSite != null)
{
if (result.Length > 0)
{
result += Separator;
}
result += exception.TargetSite.Name;
}
exception = exception.InnerException;
}
return result;
}