-
Notifications
You must be signed in to change notification settings - Fork 89
Surroundwith
Alex Zimin edited this page Jul 11, 2011
·
3 revisions
The surroundwith macro is macro which can help you to emulate "using"-like behavior.
You can define surround by DefineSurround macro and use name (defined by DefineSurround) in surroundwith.
The DefineSurround macro has the following parameters:
- name - name of defined surround (string)
- useTryFinally - when true, try/finally expression is generated for each surroundwith.
- beforeExpr - expression to add before surrounded expression
- afterExpr - expression to add after surrounded expression
Following example demonstrates the usage of this macro:
using System.Console;
using Nemerle.Surround;
[assembly: DefineSurround("surround1", false, WriteLine("Surround1Before"), WriteLine("Surround1After"))]
[assembly: DefineSurround("surround2", false, WriteLine("Surround2Before"), WriteLine("Surround2After"))]
[assembly: DefineSurround("surround3", false, WriteLine("Surround3Before"), WriteLine("Surround3After"))]
module Test
{
Main() : void
{
surroundwith (surround1, surround2, surround3)
WriteLine("Test1");
WriteLine();
surroundwith (surround1)
WriteLine("Test2");
WriteLine();
surroundwith (surround1)
surroundwith (surround2)
WriteLine("Test3");
}
}
Surround1Before Surround2Before Surround3Before Test1 Surround3After Surround2After Surround1After Surround1Before Test2 Surround1After Surround1Before Surround2Before Test3 Surround2After Surround1After