Is there a way of using one method to handle others to avoid code duplication?
- by Artur
I wonder if there is a way of writing a method or a class that would add to any method some code that is shared between many methods. The methods return different things and some of them are just void.
Below is a part of the code that is duplicated in the methods.
StartTimer(MethodBase.GetCurrentMethod().Name);
try
{
// Actual method body
}
catch (Exception ex)
{
bool rethrow = ExceptionPolicy.HandleException(ex, "DALPolicy");
if (rethrow)
{
throw;
}
}
finally
{
StopTimer(MethodBase.GetCurrentMethod().Name);
}
Any help would be greatly appreciated.