The OnPostRender Event

The OnPostRender event is fired after CodeSmith has merged metadata with your template to produce the output. You can use this event to perform any additional processing you would like after CodeSmith has finished its job. For example, the StoredProcedures.cst sample template included with CodeSmith uses this event to autoexecute the generated SQL script:

protected override void OnPostRender(string result)
{
    if (this.AutoExecuteScript)
    {
        // execute the output on the same database as the source table.
        CodeSmith.BaseTemplates.ScriptResult scriptResult = CodeSmith.BaseTemplates.ScriptUtility.ExecuteScript(
            this.SourceTable.Database.ConnectionString,
            result,
            new System.Data.SqlClient.SqlInfoMessageEventHandler(cn_InfoMessage));

        Trace.Write(scriptResult.ToString());
    }

    base.OnPostRender(result);
}