Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Home

hiredgunhouse edited this page · 12 revisions

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:

  1. Tweaking a compiled assembly for which you do not have the source code and must support/modify
  2. Adding instrumentation logic to an assembly for test purposes, which will not always be part of the release version
  3. Implementing tedious interfaces or patterns that get in the way of the simplicity of your coding efforts when directly implemented.

We developed Afterthought specifically based on our experience with PostSharp. While we enjoyed PostSharp and the advantages it provides, this product has two downsides:

  1. 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. 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. Lastly, your application is required to have a runtime dependency on PostSharp assemblies.

  2. PostSharp is no longer free for complex scenarios. 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 with no licensing constraints.

So, what does Afterthought do? Quite simply, it allows you to:

  1. Create type amendments by subclassing Amendment<,> to describe what changes you want to make
  2. Amend properties, methods, constructors and events by either adding new ones or modifying the logic of existing ones
  3. Add attributes to types, properties, methods, events, constructors and fields
  4. Implement interfaces directly on a type leveraging existing properties/methods, adding new properties/methods, and allowing Afterthought to automatically implement everything else
  5. Add attributes implementing IAmendmentAttribute to target types or an entire assembly, indicating which types to amend and what amendments to apply
  6. Configure your project to call Afterthought as a post-build step to apply the changes

Here is an example of an amendment implementation:

    public class TestAmendment<T> : Amendment<T,T>
    {
        public TestAmendment()
        {
            // Implement IMath interface
            Implement<IMath>(

                // Pi
                Properties.Add<decimal>("Pi", (instance, property) => 3.14159m),

                // Subtract()
                Methods.Add("Subtract", (T instance, decimal x, decimal y) => x - y)
            );
        }
    }

Now, you might want to start with: Step 1: Get Afterthought

Something went wrong with that request. Please try again.