Can I use the decorator pattern to wrap a method body?

后端 未结 7 1930
醉话见心
醉话见心 2020-12-10 11:01

I have a bunch of methods with varying signatures. These methods interact with a fragile data connection, so we often use a helper class to perform retries/reconnects, etc.

相关标签:
7条回答
  • 2020-12-10 11:34

    It seems like what you want is similar to behavior of an IoC container or test runner framework, where it isn't actually executing from your assembly, but is running a dynamically emitted assembly built around your code. (Smarter folks than I have called this AOP in other answers)

    So maybe in a stub for your app you could scan the other assemblies, build those emitted assemblies (which call MyHelper.PerformCall with the body of the decorated methods) then your program runs against the emitted code.

    By no means would I start down the road of trying to write this without evaluating whether some existing AOP framework could accomplish what you need. HTH>

    0 讨论(0)
提交回复
热议问题