4

This can be a debugging/monitoring process.

I want to know a way, preferably the best way, of calling a method every time other methods in a class/namespace/application are executed.

Code snippets, opinions and articles would be appreciated.

Matthew Strawbridge
  • 19,940
  • 10
  • 72
  • 93
Kasrak
  • 1,509
  • 4
  • 24
  • 48

2 Answers2

6

AOP; look at PostSharp, for example, which offers this type of weaving. Note that this approach works by chaning the IL during the build process, and may impact runtime performance if over-used.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • Thanks Mark, As I was searching I cam up with this platform, I was not familiar with this approach, Should I have make any changes in the structure of the project ? – Kasrak Dec 03 '11 at 09:52
  • 1
    @Sypress you would just have to add an assembly attribute (an "aspect"). – Marc Gravell Dec 03 '11 at 09:55
1

Take a look at Aspect Oriented Programming(AOP). A good library for this is Postsharp.

Darren Lewis
  • 8,338
  • 3
  • 35
  • 55