2

This might have been answered here before and I'm just not searching for the right thing. If so I apologize.

What I'd like to do is to automatically execute a method when any method of a class gets called and finishes executing.

Any idea how i could accomplish this? I looked into Reflection, but not sure if that would work out.

Any help appreciated :-)

StefanS
  • 876
  • 1
  • 12
  • 21
  • 5
    I answered this quite throughly here: http://stackoverflow.com/questions/1331851/dynamic-interception-of-calls-in-net – Sam Saffron Nov 30 '09 at 12:33

3 Answers3

2

If you are in a position to / it makes sense to do something in your compile process, PostSharp or Mono.Cecil are good tools for doing AOP at build time.

Otherwise go +1 Sam's answer

Community
  • 1
  • 1
Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
1

You can use Aspect Oriented Programming framework, like PostSharp.

Vitaliy Liptchinsky
  • 5,221
  • 2
  • 18
  • 25
1

You could use a callback.

void SomeMethod ( delegate MyDelegate )
{

// do some things

MyDelegate(); // execute method referenced by delegate 
}

Your method you want to automatically execute when SomeMethod finishes you pass through a delegate in SomeMethod.

Tony The Lion
  • 61,704
  • 67
  • 242
  • 415