Intercept method calls

前端 未结 6 1282
故里飘歌
故里飘歌 2020-12-06 08:30

Is there a way of intercepting some method calls without making any code changes around the method itself?

I don\'t need to inject any custom behaviour at runtime,

6条回答
  •  北海茫月
    2020-12-06 08:47

    What you are looking for is Fody: https://github.com/fody

    Its open source, stable and has lots of plugins for different AOP use cases. I am using it in a huge commercial application, and it is working very well. Installation and configuration is super easy and done within some minutes via nuget.

    Some example plugins are:

    • PropertyChanged: (Injects INotifyPropertyChanged code into properties at compile time)
    • Anotar (Simplifies logging through a static class and some IL manipulation)
    • Method Timer (Injects some very basic method timing code)
    • ... and many more!

    Requirements, examples and docs can be found on fodys github pages.

提交回复
热议问题