I want to create my custom statements for the c# compiler to generate a try finally block. Just like the lock statement.
Forexample
private readonly ReaderWriterLockSlim _lockObject
private void MyMethod()
{
MyWriteLock(lockObject)
{
}
}
private void MyMethod2()
{
MyReadLock(lockObject)
{
}
}
Compiler should generate following code for me
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();
}
}