PostSharp Aspect Framework
Automation of custom design patterns.
.NET Framework 2.0, 3.5, 4.0, 4.5
Silverlight 4, 5
Windows Phone 7.5, 8
Windows Store 8
PostSharp Express (limited)
Nearly 20 years after the Gang of Four theorized design patterns, mainstream languages such as C# still force developers to write code at an irrelevant level of abstraction.
In what may be the largest use of copy-paste inheritance in the industry, manual implementation of design patterns results in the mass production of boilerplate code, adding to the cost of developing and maintaining applications.
Many are unaware an advanced compiler technology exists that allows engineers and architects to automate the implementation of design patterns by encapsulating them into reusable components.
The technology is called Aspect-Oriented Programming (AOP), and it's backed by more than 20 years of research and industry practice.
PostSharp has provided the best of AOP to Microsoft .NET developers since 2004.
How does it work?
It's not magic: first get things clear in your head, then translate your ideas into code.
- Think about how you would explain the pattern to your colleague.
- Grab a pencil and, in plain English, write what needs to be transformed (e.g., all public methods) and how (e.g., add a try/catch block and call the exception handling service).
- Translate your ideas into code: create an aspect class and add building blocks for each code transformation.
- Apply the aspect to your business code.
- Build your project.
Think of PostSharp as a compiler extension. It applies the transformations exactly as you ordered and, under the hood, PostSharp integrates with MSBuild and post-processes the compiler output.
Catch exceptions before they get passed to the client code with OnExceptionAspect.
Property & Field Interception
Override Get and Set semantics on properties and fields with LocationInterceptionAspect.
Validate values assigned to fields, properties or parameters with LocationValidationAspect.
Dynamically add custom attributes to existing code using CustomAttributeIntroductionAspect.
Dynamically add manage resources to the assembly using ManagedResourceIntroductionAspect.