3

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 ?

Community
  • 1
  • 1
jwaliszko
  • 16,942
  • 22
  • 92
  • 158
  • Analogical question I've asked, but with much more detailed answers received is here: http://stackoverflow.com/questions/14307298/basic-implementation-of-aop-like-attribute-using-standard-net-framework – jwaliszko Jan 14 '13 at 09:47

1 Answers1

3

That's an example of aspect oriented programming where Wrap is an aspect.

C# has no built in support for aspect oriented programming, but there are addons such as postsharp that supports it.

Anders Abel
  • 67,989
  • 17
  • 150
  • 217