Suggestions for making a reusable try/catch block in C#?

后端 未结 5 1707
故里飘歌
故里飘歌 2021-01-30 09:33

I have a class that has about 20-some methods in it. Each one does some web service message processing. I just had to make a change to it, and realized that every one of these m

5条回答
  •  一个人的身影
    2021-01-30 10:04

    You've identified a cross-cutting concern. You could employ an aspect-oriented programming (AOP) approach to this problem. This can either be performed at runtime by using a proxy that sits in front of your class or during compilation by using an AOP tool that modifies the compiled code.

    In the past I've made use of Castle Dynamic Proxy to do this (at runtime). Alternatively you could use one of the other AOP frameworks such as PostSharp.

提交回复
热议问题