私はさまざまなコンテンツを持っていますが、パラメータは同じで、内部をキャッチしようとするとほとんど同じです。冗長コードを減らすことができるように関数をラップする方法はありますか?ジェネリック関数ラッパー
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#lambda 'を検索するためにそれらを既に知っていなければ、私はあなたを招待します。 –
Kilazur