Afterthought allows developers to post-process .NET assemblies to add code that either cannot be added to the original source or is not convenient/efficient to do so. Examples include:
We developed Afterthought specifically based on our experience with PostSharp. While we enjoyed PostSharp and the advantages it provides, this product has two downsides:
The developer experience is a bit complicated, introducing new concepts like aspects and generally requiring you to understand how PostSharp works internally to make it work for you. It required you to frequently cast objects to known types instead of writing fluent strongly-typed intuitive code. Lastly, the emitted code to do something very simple is very complex--dozens of lines of code just to call one line of your own code.
PostSharp is no longer free. We have been developing open-source libraries for the past couple of years, and as we prepared to release them publically, we realized that some dependencies on PostSharp made our own open source efforts less appealing. The introduction of Afterthought eliminates this issue by providing a completely free option.
So, what does Afterthought do? Quite simply, it allows you to:
Amendment<,>
to describe what changes you want to make
IAmendmentAttribute
to target types or an entire assembly, indicating which types to amend and what amendments to apply
Here is an example of an amendment implementation:
public class TestAmendment<T> : Amendment<T,T> { public override void Amend() { // Implement IMath interface ImplementInterface<IMath>( // Pi new Property<decimal>("Pi") { Getter = (instance, property) => 3.14159m }, // Subtract() Method.Create("Subtract", (T instance, decimal x, decimal y) => x - y) ); } }