我有4个方法,它们的代码相似
private void LogExceptions(ObjA.Input input, int customerId)
{
//ObjA is a big object, thats why I try not to send the whole object in this method
Log(input);
Log(ObjA.Exceptions);
}
private void LogExceptions(ObjB.Input input, int customerId)
{
//ObjB is a big object, thats why I try not to send the whole object in this method
Log(input);
Log(ObjB.Exceptions);
}
等等
我无法将它变成模板方法,比如
private void LogExceptions<T1,T2>(T1 input, int customerId) whereas T1:ObjA.Input,ObjB.Input
{
Log(T1);
Log(T2);
}
如何做或者有其他方法吗?非常感谢您的帮助。
我认为我的问题无法得到正确的答案......这是精确的代码....
private void LogExceptions(AccARef.Response response)
{
StringBuilder sbErrors = null;
if (response.ValMethod != null && response.ValMethod.IsValid == false)
{
if (response.ValMethod.Errors.Count() > 0)
{
sbErrors = new StringBuilder();
foreach (AccARef.Exception exp in response.ValMethod.Errors)
{
sbErrors.Append(" * " + exp.Message + exp.StackTrace + " ");
Console.WriteLine(strError.ToString())
}
}
}
}
private void LogExceptions(AccBRef.Response response)
{
StringBuilder sbErrors = null;
if (response.ValMethod != null && response.ValMethod.IsValid == false)
{
if (response.ValMethod.Errors.Count() > 0)
{
sbErrors = new StringBuilder();
foreach (AccBRef.Exception exp in response.ValMethod.Errors)
{
sbErrors.Append(" * " + exp.Message + exp.StackTrace + " ");
Console.WriteLine(strError.ToString())
}
}
}
}
现在AcctBRef和AcctARef无法实现共同的接口,因为它们不是我的对象。或者如果它们不是我的对象,我仍然可以装饰它们成为我的对象吗?
ObjB.Exceptions
жҳҜдёҖдёӘйқҷжҖҒи°ғз”Ёеҗ—пјҹ - Davin Tryon