より一般的には、パラメータ化されるタイプのターゲットがトップレベルのプロパティではない場合に、どのように汎用ルーチンを作成するのか疑問に思っています。
具体的には、次の2つの機能から重複を排除することに取り組んでいます。
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;
}