MSBUILD and Codegen

MSBuild and the code generation techniques of Kathleen Dollard seem to fit together very naturally.

MSBuild is a blatant clone of NAnt with the benefit of being the native project file format of VS2005.

Kathleen Dollard promotes the use of code generation (generated code = meta data + templates) using XSLT.

Kathleen has a complex code generation harness that provides configurable one touch code generation.

I feel that this would be more naturally implemented as a set of MsBuild/Nant extensions.

For example the Database Metadata extraction tool would be one task. Stored procedure generation would be another. Code to call the stored procedures would be a third. This would provide the one touch benefit of the generation framework yet allow the pieces to become far more flexible.

C Sharp Method Group Conversions

// The following is a simple example of event handlers without having to declare new’s 

using System;

namespace DelegateConsole
{
    public class SimpleMaths
    {
        public delegate void MathsMessage(string msg);
        public event MathsMessage ComputationFinished;

        public int Add(int x, int y)
        {
            ComputationFinished(“Adding Complete”);
            return x + y;
        }
        public int Subtract(int x, int y)
        {
            ComputationFinished(“Subtracting Complete”);
            return x – y;       
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            SimpleMaths s = new SimpleMaths();
            // Method group conversion – almost a delphi event handler
            s.ComputationFinished += ComputationFinishedHandler;
            Console.WriteLine(“10 + 10 is {0}”,s.Add(10,10));
            Console.ReadLine();
        }

        static void ComputationFinishedHandler(string msg)
        {
            Console.WriteLine(msg);
        }
    }
}