Created
July 13, 2012 15:28
-
-
Save vasily-kirichenko/3105479 to your computer and use it in GitHub Desktop.
Not null in Nemerle
This file contains 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
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