Code Snippet for ArgumentNullException

I got a chance to see BradA give his talk at TriNUG Wednesday night, and in honor of that (specifically, the part where he explains why an API may do a disservice to its consumers if it needs an argument to be non-null and just lets null refs happen instead of argument checking) is a quickie snippet for ArgumentNullException throwing on null parameters.

It’s obviously not ground-breaking stuff, but hopefully the easier that adding the checking becomes on developers, the more likely it is they’ll provide it, right? 🙂

<?xml version=1.0 encoding=utf-8 ?>

<CodeSnippets  xmlns=>

  <CodeSnippet Format=1.0.0>


      <Title>argument null check</Title>


      <Description>Code snippet for checking a parameter for null and throwing an ArgumentNullException</Description>

      <Author>Microsoft Corporation</Author>









          <ToolTip>Parameter to do the null check for</ToolTip>




      <Code Language=csharp>

        <![CDATA[if ($parametername$ == null)


            throw new ArgumentNullException(“$parametername$”);








Comments (0)

Skip to main content