Is there a way of using one method to handle others to avoid code duplication?
Posted
by Artur
on Stack Overflow
See other posts from Stack Overflow
or by Artur
Published on 2010-04-15T14:27:59Z
Indexed on
2010/04/15
14:33 UTC
Read the original article
Hit count: 386
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.
© Stack Overflow or respective owner