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();
}
]>
}
}