How do i create my custom lock statement in c#?
<p>I want to create my custom statements for the c# compiler to generate a try finally block.
Just like the lock statement.</p>

<p>Forexample </p>

<pre><code>private readonly ReaderWriterLockSlim _lockObject

private void MyMethod()
{
   MyWriteLock(lockObject)
   {

   }
}

private void MyMethod2()
{
   MyReadLock(lockObject)
   {

   }
}
</code></pre>

<p>Compiler should generate following code for me</p>

<pre><code>private void MyMethod()
{
   try
   {
     lockObject.EnterWriteLock();
     .. statetments for the method    
   }
   finally 
   {
     _lockObject.ExitWriteLock();
   }
}

private void MyMethod2()
{
   try
   {
     lockObject.EnterReadLock();
     .. statetments for the method    
   }
   finally 
   {
     _lockObject.ExitReadLock();
   }
}
</code></pre>
