Last active
July 19, 2018 03:40
-
-
Save qwertie/36a223f8a3b9826c9cb7e1e429ca17f8 to your computer and use it in GitHub Desktop.
LeMP macro to expand the C# `using` statement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define a macro recognized by LeMP ( http://ecsharp.net/lemp ) | |
define #using($type $varname = $expression, $block) { | |
{ | |
$type $varname = $expression; | |
try $block | |
finally { | |
if ($varname != null) | |
((IDisposable)$varname).Dispose(); | |
} | |
} | |
} | |
// This will be expanded | |
using (Font font1 = new Font("Arial",10f)) { | |
byte charset = font1.GdiCharSet; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment