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
- runtime
realproxy
based aop - runtime subclass/virtual method aop
- post compile il weave aop
- 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
Post a Comment