Skip to content

Instantly share code, notes, and snippets.

@RobSeder
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobSeder/6f9a5ac1d67144dbff68 to your computer and use it in GitHub Desktop.
Save RobSeder/6f9a5ac1d67144dbff68 to your computer and use it in GitHub Desktop.
Visual Studio snippets I use. See this blog post for more detail: http://blog.robseder.com/2014/10/15/common-visual-studio-snippets-i-use/
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>argNull</Title>
<Author>RobSeder@outlook.com</Author>
<Description>Snippet to check an argument for null, and throw an appropriate exception.</Description>
<HelpUrl>http://blog.robseder.com/2014/10/15/common-visual-studio-snippets-i-use/</HelpUrl>
<Shortcut>argNull</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>ArgName</ID>
<ToolTip>ArgName</ToolTip>
<Default>ArgName</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[if ($ArgName$ == null)
throw new ArgumentNullException("$ArgName$");]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>argString</Title>
<Author>RobSeder@outlook.com</Author>
<Description>Snippet to check a string argument for null or whitespace, and throw an appropriate exception.</Description>
<HelpUrl>http://blog.robseder.com/2014/10/15/common-visual-studio-snippets-i-use/</HelpUrl>
<Shortcut>argString</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>ArgName</ID>
<ToolTip>ArgName</ToolTip>
<Default>ArgName</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>", "</ID>
<ToolTip>", "</ToolTip>
<Default>", "</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[if (String.IsNullOrWhiteSpace($ArgName$))
throw new ArgumentException("Argument \"$ArgName$\" cannot be null or empty.", "$ArgName$");]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>exceptionProper</Title>
<Author>RobSeder@outlook.com</Author>
<Description>Snippet to create a proper exception class; implementing all standard constructors, and includes XML code comments.</Description>
<HelpUrl>http://blog.robseder.com/2014/10/15/common-visual-studio-snippets-i-use/</HelpUrl>
<Shortcut>exceptionProper</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>NameSpace</ID>
<ToolTip>NameSpace</ToolTip>
<Default>NameSpace</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>Name</ID>
<ToolTip>Name</ToolTip>
<Default>Name</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>Parent</ID>
<ToolTip>Parent</ToolTip>
<Default>Parent</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[/// <summary>
/// Exception class for the $NameSpace$.$Name$ namespace.
/// </summary>
public class $Name$Exception : $Parent$Exception
{
/// <summary>
/// Creates a new instance of this type.
/// </summary>
public $Name$Exception()
{
}
/// <summary>
/// Creates a new instance of this type.
/// </summary>
/// <param name="message">The message to include with this exception.</param>
public $Name$Exception(string message) : base(message)
{
}
/// <summary>
/// Creates a new instance of this type.
/// </summary>
/// <param name="message">The message to include with this exception.</param>
/// <param name="inner"></param>
public $Name$Exception(string message, Exception inner) : base(message, inner)
{
}
}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
<Title>propProper</Title>
<Author>RobSeder@outlook.com</Author>
<Description>Snippet to create a full property declaration with a backing field, in a collapsible format - with XML code comments.</Description>
<HelpUrl>http://blog.robseder.com/2014/10/15/common-visual-studio-snippets-i-use/</HelpUrl>
<Shortcut>propProper</Shortcut>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>DescriptionOfProperty</ID>
<ToolTip>DescriptionOfProperty</ToolTip>
<Default>DescriptionOfProperty</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>DataType</ID>
<ToolTip>DataType</ToolTip>
<Default>DataType</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>PropertyName</ID>
<ToolTip>PropertyName</ToolTip>
<Default>PropertyName</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>fieldName</ID>
<ToolTip>fieldName</ToolTip>
<Default>fieldName</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp" Delimiter="$"><![CDATA[/// <summary>
/// Gets or sets $DescriptionOfProperty$.
/// </summary>
public $DataType$ $PropertyName$
{
get { return _$fieldName$; }
set { _$fieldName$ = value; }
} private $DataType$ _$fieldName$ = default($DataType$);]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment