Example

The following code snippet illustrates an object model where INotifyPropertyChanged,
undo/redo, code contracts, aggregation and code contracts are all implemented using PostSharp ready-made attributes.

Multithreading is a great demonstration of the limitations of conventional object-oriented programming. Thread synchronization is traditionally addressed at
an absurdly low level of abstraction, resulting in excessive complexity and defects.

Yet, several design patterns exist to bring down the complexity of multithreading.
New programming languages have been designed around these patterns: for instance Erlang over the Actor pattern and functional programming over the Immutable pattern.

PostSharp gives you the benefits of threading design patterns without leaving C# or VB.

The attributes that implement the standard and thread safety patterns are called aspects. This term comes from the paradigm of aspect-oriented programming (AOP).
An aspect is a class that encapsulates behaviors that are injected into another class, method, field, property or event. The process of injecting
an aspect into another piece of code is called weaving. PostSharp weaves aspects at build time; it is also named a build-time aspect weaver.

PostSharp Aspect Framework is a pragmatic implementation of AOP concepts. All ready-made implementations of patterns are built using PostSharp Aspect Framework. You
can use the same technology to automate the implementation of your own patterns.

Not all patterns can be fully implemented by the compiler. Many patterns involve a lot of handwritten code. However, they are still patterns
because we want to follow the same conventions and approach when solving the same problem. In this case, we have to validate the code against
implementation guidelines of the pattern. This is typically achieved during code reviews, but as any algorithmic work, it can be partially automated
using the right tool. This is the job of the PostSharp Architecture Framework.

PostSharp Architecture Framework also contains pre-built architectural constraints that help to solve common design problems. For instance, the
InternalImplementAttribute constraint prevents an interface to be implemented
in an external assembly.

Example

Consider a form-processing application. There may be hundreds of forms, and each form can have dozens of business rules. In order to
reduce complexity, the team decides that all business rules will respect the same pattern. The team decides that each class representing a business
rule must contain a public nested class named Factory, and that this class must have an [Export(IBusinessRuleFactory)]
custom attribute and a default public constructor. The team wants all developers to follow the convention. Therefore, the team decides to create
an architectural constraint that will validate the code against the project-specific Business Rule Factory pattern.