我正在尝试“通用化”我们散布在系统周围的一些代码。
我想要:
- 返回一个泛型类型,
- 传入某种包含要调用的方法的委托。
我对泛型很陌生,所以任何帮助表示赞赏。
下面是我的手指在空中的地方(!)
public static T ReturnSingleObject<T>(Func<string, int, T> dynamicSignature)
{
T returnValue;
ServiceReference wCFService;
try
{
wCFService = new BusinessServiceClient();
returnValue = dynamicSignature();
//returnValue = wCFService.AMETHOD(PARAM1, PARAM2);
return returnValue;
}
catch (Exception)
{
if (wCFService != null) wCFService.Abort();
throw;
}
finally
{
if (wCFService != null) wCFService.Close();
}
}