PostSharp is the only aspect framework that brings all the advantages of AOP to
the Microsoft .NET framework. PostSharp is an easily extensible framework that works
with mainstream .NET languages, such as C# or Visual Basic.
The PostSharp aspect framework has many advantages over other aspect frameworks,
as detailed in the following explanation of features and benefits.
Plain C#, Visual Basic, and LINQ
PostSharp does not force you to learn a new language, nor does it rely on obscure
XML files. In PostSharp, aspects are plain C# or Visual Basic classes, and aspects
are conveniently applied to source code using custom attributes (annotations), or
in more complex cases, Linq (language-integrated query) expressions.
Within minutes, with no background in AOP, you are writing your own aspects.
All features of Visual Studio, or popular productivity add-ins like Resharper or
DevExpress, work with aspects just as with other code – including refactoring or
debugging.
Rich Aspect Semantics
Because of the unique possibilities and expressivity offered by PostSharp for developing
aspects, you can use aspects to automate the implementation of a large range of
design patterns.
With Postsharp, you can do the following inside aspects:
- Intercept methods, properties, fields, and events.
- Execute code on method entry, success, or failure.
- Introduce methods, properties, events, and interfaces to target types.
- Import methods, properties and events of target types into the aspect.
- Implement abstract or external methods.
- Use Linq or plain C# over reflection to select aspect targets.
- Support complex aspects (using advice and pointcuts).
- Inherit aspects (for classes and virtual/abstract methods).
Visual Studio Extension
Not only does PostSharp integrate with the Visual Studio build process, it also
adds the following features to the Visual Studio user interface:
- Aspect Browser – Similar in appearance to the Class View, the Aspect Browser
displays the available aspects in the upper pane, and the set of targets to which
a selected aspect is applied in the lower pane.
- Enhanced Code Elements – Code elements enhanced by aspects are lightly underlined.
Underlined elements include additional runtime behaviors besides those expressed
directly in source code.
- Intelligent Tooltips – Placing the cursor over enhanced code, displays a tooltip.
The tooltip lists all aspects and transformations applied to this code and includes
a hyperlink to relevant aspects.
By visualizing which aspects apply to a given code element, the Visual Studio extension
makes it easier to understand code behavior.
No Impact on Source Code
Run-time weavers require the instantiation of every enhanced class using a factory
method provided by the aspect framework. In many cases (for instance WPF windows
and controls), this is simply not possible.
With PostSharp, you don't have to change a single line of code.
Furthermore, where run-time weavers let you apply aspects only to public or virtual
methods, with PostSharp you can use aspects everywhere.
Easy Build Process Integration
PostSharp integrates easily into virtually any build process, including build servers.
In most cases, launching the set up program is all that’s necessary. In complex
situations, you can deploy PostSharp to the source control repository. PostSharp
integrates with Visual Studio, MSBuild, and NAnt. You can also use it as a command-line
utility.
As a result, PostSharp integrates in virtually any build environment.
Broad Platform Support
PostSharp is the only aspect framework supporting such a broad range of platforms;
You can use the same tools and patterns on all platforms.
- Microsoft .NET 2.0-4.0
- Microsoft Azure
- Novell Mono 2.3
- Microsoft Compact Framework .NET 2.0-3.5
- Microsoft Silverlight 2.0-3.0
Build-Time Technology
PostSharp runs at build-time to integrate aspect code into the code produced by
standard .NET compilers, such as C# or Visual Basic.
Result: your code is fast, much faster than with run-time aspect weavers.
And there are no surprises. Using a decompiler, such as Redgate Reflector, you can
view the code PostSharp generates. This is the exact code the .NET virtual machine
will execute.
Adaptive Code Generation
PostSharp generates code for only those framework features your aspect actually
uses. You don't pay for what you don't need.
Build-Time Aspect Validation
Aspect developers can write code that validates how and where an aspect is used.
Validation rules are enforced at build time, and the program will not compile if
aspects are used incorrectly. For instance, you can require that a thread-dispatching
aspect be used only on the instance method of objects that have thread affinity.
You can easily separate roles within your development team – aspect developers
and aspect users. Aspect users don't need to know how the aspect is implemented.
Problems are detected early. The earlier an error is detected, the less expensive
it is to fix the error.
Robust Aspect Composition
PostSharp guarantees that aspects behave consistently and predictably when many
aspects are applied to the same code element. PostSharp ensures that aspects are
ordered correctly, and that there are no aspect conflicts.
For instance, it ensures that an authorization aspect always executes before a caching
aspect, or authorization is skipped. Errors are discovered early, at build time,
instead of being diagnosed at run time, which is much more difficult.
As a result, projects scale well as they become more complex and development teams
grow.
Multi-Vendor Support
Thanks to PostSharp's robust aspect composition, a program can use aspects from
different vendors, even if they don’t know about each other, and still express dependencies
between aspects.
High Extensibility
Because PostSharp is designed as an extensible platform, you can implement new types
of low-level aspects or MSIL/bytecode transformations.
Independent vendors can implement highly-specialized aspects for operations where
performance is critical (for instance aspects for a specific instrumentation library).
And other developers can be confident that, when no simple solution is available,
it’s always possible to develop a complex solution.
Attractive Redistribution License
If you're an independent software vendor, SharpCrafters offers attractive conditions
that will allow you to redistribute PostSharp with your product.
See our redistribution offer.