Possible Duplicate:
C# wrap method via attributes
I’d like to achieve such functionality:
[Wrap]
public void Foo()
{
/* foo logic */
}
Where [Wrap] attribute is an attribute, which wraps function logic within some outer code – just for example let it be a transaction scope:
using(var scope = new TransactionScope())
{
/* foo logic */
scope.Complete();
}
How to write such an attribute ?
That’s an example of aspect oriented programming where
Wrapis an aspect.C# has no built in support for aspect oriented programming, but there are addons such as postsharp that supports it.