How to execute a method everytime before/after executing some other method which has many overloads?

前端 未结 2 1343
被撕碎了的回忆
被撕碎了的回忆 2021-01-06 09:51

I have an existing application which is already developed and is in use.

There are multiple overloads of one of the methods (called Read()) of a class. Now I want t

相关标签:
2条回答
  • 2021-01-06 10:17

    Have a generic method

    public void Read<T>(T t) where t:ISomeCommonInterface
    {
       Before();
       Read(t);
       After();
    }
    
    0 讨论(0)
  • 2021-01-06 10:28

    You need to use an Interceptor / AoP. The first options that jump to mind are PostSharp and Microsoft Unity.

    There's a very good article on this sort of thing in this months MSDN magazine: http://msdn.microsoft.com/en-us/magazine/gg490353.aspx

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