c# - Intercept method calls -


is there way of intercepting method calls without making code changes around method itself?

i don't need inject custom behaviour @ runtime, add custom performance logging existing project.

you want aspect oriented programming.

there 4 main flavours of aop

  1. runtime realproxy based aop
  2. runtime subclass/virtual method aop
  3. post compile il weave aop
  4. precompile source code aop

the above ordered in order of speed of execution (slowest fastest). note last 2 "should" same speed. expect compiler produce better il post compile il weave.

the first camp includes ioc containers, since lend pattern, including , not limited

  • unity
  • spring.net
  • castle.windsor
  • postsharp express

the second camp, pretty rare, , project can think of off top of head entity framework (which uses lazy loading, isn't extensible, , cannot customised).

the third camp pretty sparce also, since technique extremely complicated , difficult. works editing dll assembly after have compiled, add code want.

  • postsharp pro
  • mono.cecil
  • fody (a mono.cecil wrapper)

the final camp relatively new. new in fact, real entry experimental ms roslyn. c# compiler. so...yeah...its pretty magic.

now, if having real huge performance issues performance critical code, suggest using fody. awesome this, is free (unlike postsharp pro), uses nuget , there performance tool in fody.methodtimer.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -