-->

c# trigger pre and post method calls like mvc acti

2019-08-03 04:54发布

问题:

Is there a way to get the functionality of action filters in asp.net mvc where you can call and manipulate action parameters pre the method executing and post method call to update/view the return type data but in a standard c# class library class method?

回答1:

This sounds a lot like aspect-oriented programming. PostSharp is an example of a tool that can help you get there. A common example is to have a class auto-implement INotifyPropertyChanged, which is boring or tedious, or to spit out a bunch of logging statements before and after a method call, without having to manually write that instrumentation in code.

Hope that gets you on the right track.