Transactions for C# objects?
<p>Just curious, is there any support for transactions on plain C# objects? Like</p>

<pre><code>using (var transaction = new ObjectTransaction(obj))
{
  try
  {
    obj.Prop1 = value;
    obj.Prop2 = value;
    obj.Recalculate(); // may fire exception
    transaction.Commit(); // now obj is saved
  }
  except
  {
     transaction.Rollback(); // now obj properties are restored
  }
}
</code></pre>

<p>Just to make answers more useful ;-) is there anything similar in other languages?</p>

<p>Update on STM: here's what it claims:</p>

<pre><code>atomic {
  x++;
  y--;
  throw;
}
</code></pre>

<p>will leave x/y unchanged, including chained methods calls. Looks like what I ask for. At least it's very interesting. I think that's close enough. Also, there're similar things in other languages, for example Haskell STM. Notice I don't say that it should be used for production ;-)</p>
