Skip to content

Instantly share code, notes, and snippets.

@kzu
Last active March 25, 2020 13:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzu/d207b335469527bd97b7 to your computer and use it in GitHub Desktop.
Save kzu/d207b335469527bd97b7 to your computer and use it in GitHub Desktop.
ArgumentNullException C# Code Snippet
<?xml version="1.0" encoding="utf-8" ?>
<!--
Template for a null check for a parameter.
Press notnull[TAB][TAB] to get it.
Copy to Documents\Visual Studio 2015\Code Snippets\Visual C#\My Code Snippets\notnull.snippet
Restart VS
-->
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Guard null argument</Title>
<Shortcut>notnull</Shortcut>
<Description>Throw ArgumentNullException for the given argument</Description>
<Author>Daniel Cazzulino</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Imports>
<Import>
<Namespace>System</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>argument</ID>
<ToolTip>Name of the argument to guard</ToolTip>
<Default>value</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[if ($argument$ == null) throw new ArgumentNullException(nameof($argument$));
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment