Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cool PostSharp aspects [closed]

I'm looking for interesting PostSharp aspects - anything that you found useful and wouldn't mind sharing.

like image 835
Dmitri Nesteruk Avatar asked Feb 01 '09 23:02

Dmitri Nesteruk


2 Answers

The coolest aspect of it for me is that it can help me implement the single responsibility principle:

"In object-oriented programming, the single responsibility principle states that every object should have a single responsibility, and that all its services should be narrowly aligned with that responsibility."

I hope to adopt this more fully with more experience in the future, but for now, I have just started with having it built in to my logging needs:

together with Log4PostSharp, I can do:

[Log(LogLevel.Info, "Counting characters.")]
int CountCharacters(string arg) {
   return arg.Length;
}

What this means is that, the responsibility of logging is ascribed elsewhere (coding wise), and injected from a separate source by PostSharp and Log4PostSharp magic.

like image 188
Ric Tokyo Avatar answered Oct 05 '22 05:10

Ric Tokyo


D. Patrick Caldwell has some cool ideas on his blog.

Validate Parameters Using Attributes and PostSharp http://dpatrickcaldwell.blogspot.com/2009/03/validate-parameters-using-attributes.html

  • Implmementing Coding Contracts using PostSharp.

Memoizer Attribute Using PostSharp http://dpatrickcaldwell.blogspot.com/2009/02/memoizer-attribute-using-postsharp.html

  • Basically, a light-weight field-value caching mechanism.
like image 23
Mike Hall Avatar answered Oct 05 '22 04:10

Mike Hall