Can I use the decorator pattern to wrap a method body?
Posted
by mgroves
on Stack Overflow
See other posts from Stack Overflow
or by mgroves
Published on 2010-06-03T14:10:04Z
Indexed on
2010/06/03
14:14 UTC
Read the original article
Hit count: 195
I have a bunch of methods with varying signatures. These methods interact with a fragile data connection, so we often use a helper class to perform retries/reconnects, etc. Like so:
MyHelper.PerformCall( () => { doStuffWithData(parameters...) });
And this works fine, but it can make the code a little cluttery. What I would prefer to do is decorate the methods that interact with the data connection like so:
[InteractsWithData]
protected string doStuffWithData(parameters...)
{
// do stuff...
}
And then essentially, whenever doStuffWithData
is called, the body of that method would be passed in as an Action
to MyHelper.PerformCall()
. How do I do this?
© Stack Overflow or respective owner