2
我有许多不同内容的函数,但参数和try catch里面差不多。无论如何要将功能封装起来以便减少冗余代码。通用函数包装
ResponseStatus GetPotatoList(GetPotatosRequest requestParam, out GetPotatosResponse response, out ResponseErrorType errorType)
{
ResponseStatus status = ResponseStatus.Fail;
response = new GetPotatosResponse();
//To Do
try
{
//To Do
status = ResponseStatus.Success;
}
catch(CustomException ex)
{
errorType = ResponseErrorType.CustomError;
}
catch(TimeoutException ex)
{
errorType = ResponseErrorType.Timeout;
}
catch(Exception ex)
{
errorType = ResponseErrorType.GeneralFailure;
}
return status;
}
是否有可能访问action1()和action2()内部的值? –
@Amigo你为什么需要它?例如,如果你需要传递参数,你可以使用类型化的Action:'Action',你可以像这样设置:'(myInt)=> doSomething(myInt)'并且像这样使用它:'action1(213 );';我邀请你,如果你不知道他们已经搜索了'C#lambdas'来理解它是如何工作的。 –
Kilazur