Skip to content

Instantly share code, notes, and snippets.

@vasily-kirichenko
Created July 13, 2012 15:28
Show Gist options
  • Save vasily-kirichenko/3105479 to your computer and use it in GitHub Desktop.
Save vasily-kirichenko/3105479 to your computer and use it in GitHub Desktop.
Not null in Nemerle
public macro not_null(obj)
syntax ("not_null", obj)
{
def var_name = $"$obj";
<[
when ($obj == null)
throw System.ArgumentNullException($var_name);
$obj;
]>
}
class Person
{
public Name: string;
public this(name: string)
{
Name = not_null name;
}
}
// causes ArgumentNullException exception with argument name set to "name"!
def person = Person(null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment