# Saturday, November 08, 2008
« Nemerle Macros - Record | Main | Nemerle Macros - InheritConstructors »

This is a simple macro I use to make transactions feel like apart of the Nemerle language.

Watch the Screencast

Before

using System;
using System.Transactions;
 
namespace Demo
{
    module Program
    {
        Main() : void
        {
            using (trans = TransactionScope())
            {
                // Do some stuff in a transaction
                // ...
 
                // Remember to call Complete when finished!
                trans.Complete();
            }
        }
    }
}

After

using System;
using System.Transactions;
using SampleMacros;
 
namespace Demo
{
    module Program
    {
        Main() : void
        {
            transaction 
            {
                // Do some stuff in a transaction
                // ...
 
            }
        }
    }
}

transaction.n

using System;
using System.Transactions;
 
namespace SampleMacros
{
    public macro transaction(block) syntax ("transaction", block)
    {
        <[ 
            using (t = TransactionScope()) {
                $block;
                t.Complete();
            }
        ]>
    }
}
Saturday, November 08, 2008 5:08:54 PM (GMT Standard Time, UTC+00:00)  #    Disclaimer  |  Comments [0]  | 
Comments are closed.