Cool PostSharp aspects [closed]
Asked Answered
M

3

15

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

Microprint answered 1/2, 2009 at 23:48 Comment(0)
D
4

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.

Discography answered 2/2, 2009 at 2:20 Comment(0)
C
4

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.
Cactus answered 6/5, 2009 at 17:55 Comment(0)
B
0

Daft question, but isn't that the purpose of the Contributions Directory?

There is an example of automatic property-change implementation - INotifyPropertyChanged.

Braze answered 2/2, 2009 at 9:2 Comment(1)
Actually, there's one in PostSharp's examples, but it's buggy. Had to rework that a little.Microprint

© 2022 - 2024 — McMap. All rights reserved.