I'm trying to 'genericize' some code we have spattered around our system.
I want to:
- return a generic type,
- pass in some kind of delegate containing the method to be called.
I'm pretty new to generics so any help appreciated.
Below is where my finger in the air is(!)
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();
}
}