PostSharp是一个可以减少代码行数并且可以改进合乎逻辑的耦合,因此他可以帮助我们建立更稳定、更清洁的设计和更廉价的源代码维护。
最值得称道的是PostSharp是免费的开源的,甚至可以用在商业中
PostSharp makes more with less code. How?
Have you already implemented things like transaction management, logging, caching, or security? In each method, you had to write a same dozen of lines of code, right?
With PostSharp, you can encapsulate these aspects as custom attributes. You can make your own custom attributes that will really add new behaviors to your code! This is sometimes called aspect-oriented programming (AOP) or policy injection.
Sounds Incredible. Show me!
Here is a tracing custom attribute:
public class SimplestTraceAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionEventArgs eventArgs)
{
Trace.TraceInformation("Entering {0}.", eventArgs.Method);
Trace.Indent();
}
public override void OnExit( MethodExecutionEventArgs eventArgs)
{
Trace.Unindent();
Trace.TraceInformation("Leaving {0}.", eventArgs.Method);
}
}
And if you have 5 minutes left,
look at this video.
How Does it Work?
PostSharp transparently inserts itself in the build process and post-processes the compiled assembly. Since PostSharp works at MSIL level, it supports virtually all static languages targeting the .NET Framework.
Is That All?
No, you've seen only a small bit of PostSharp! With PostSharp, you can:
* Execute something before, after or on exception of the execution of any method in your assembly (it's the example above).
* Intercept calls to any method from your assembly - you get a delegate to the hooked method.
* Add behaviors to fields or even replace fields by a storage manager of your own.
* Compose interfaces into types.
* Define your own handler for external methods. Exactly! It means that you can now define SQL stored procedures as external in C# or VB.NET.
Is That Really All?
No, it's only the top of the iceberg. What I've featured above is provided by PostSharp Laos, which is only a plug-in built on the top of PostSharp Core.
Where PostSharp Laos provides high-level functionalities for end users, it rests on PostSharp Core for the hard work.
If you need a transformation that PostSharp Laos does not provide off-the-shelf, you can implement yourself using PostSharp Core.
Download PostSharp 1.0 RC 2
Download PostSharp, the leading static aspect weaver for the .NET Framework. Choose the package that is best for you. The Windows Installer is definitively the fastest way to get started. But if you don't like global installation, you will prefer the light binary package. And if you want to look how is done, get the source package!
If you like PostSharp, you will love its plug-ins! Are you a user of Enterprise Library, Spring.NET, ADO.NET Entity Framework, log4net? Look how your favorite development libraries get stronger when they work together!
Windows Installer
definitively the fastest way to get started!PostSharp-1.0.8.316-Installer.zip (5.7 MB)
Daily Builds
looking for a bug fix? you are at the right address. but warning: work ongoing! http://download.postsharp.org/builds/Binary - No Installer
not a fan of global installations? download this package and learn in the doc how to perform a per-project installation.PostSharp-1.0.8.316-Binary.zip (0.9 MB
Source Distribution
curious of how it works? PostSharp-1.0.8.316-Source.zip (1.5 MB)
官方网站:
http://www.postsharp.org/