Skip to content

Instantly share code, notes, and snippets.

@qwertie
Last active July 19, 2018 03:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwertie/36a223f8a3b9826c9cb7e1e429ca17f8 to your computer and use it in GitHub Desktop.
Save qwertie/36a223f8a3b9826c9cb7e1e429ca17f8 to your computer and use it in GitHub Desktop.
LeMP macro to expand the C# `using` statement
// 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