The snippet above will insert the textif (argName == null) throw new ArgumentNullException("argName");into the current cusror position, when you write the snippet title xnull. Changing the argument name in one place, will change it in the second place too. In order to use it, create a file named xnull.snippet in one of the snippets subdirectories (usually, C:\Program Files\Microsoft Visual Studio 10.0\VC#\Snippets\1033\*) and paste the code into it.
Thursday, April 22, 2010
VS.Net 2010 C# Code Snippet for throwing ArgumentNullException
When you receive an argument in a public method, you often need to throw an ArgumentNullException if its value is null. Currently there is no snippet in VS.Net 2010 to do that.
Luckily, it is very easy to construct one:
Subscribe to:
Posts (Atom)