1

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?

monkeylee
  • 965
  • 3
  • 15
  • 32
  • 1
    possible duplicate of [C# Attribute to trigger an event on invoking a method](http://stackoverflow.com/questions/226420/c-sharp-attribute-to-trigger-an-event-on-invoking-a-method) – Patrick Hofman Mar 03 '15 at 09:58

1 Answers1

2

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.

Nicholas Piasecki
  • 25,203
  • 5
  • 80
  • 91
  • Tons of great examples here: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=postsharp+asp.net+mvc – John Farrell Nov 18 '10 at 22:20
  • any open source alternative to postsharp you would recommend? – monkeylee Nov 18 '10 at 22:39
  • I feel like PostSharp was open source at one time ... maybe it was just free to use. It looks like there is still a community edition that is free. I have used PostSharp in the past and it seems to work well. At a basic level, you could use Castle's DynamicProxy or LinFu, but the use case is different. At least now you know the magic words to search for! :) – Nicholas Piasecki Nov 18 '10 at 23:21