A previous tip of the week mentioned how to use the SimpleTypeName() snippet function.  Here’s how to use the SimpleTypeName() function alongside the ClassName() function.  The ClassName() function will automatically substitute the name of the outer class. 

For example, if you had

class Class1



You could make a snippet that used the ClassName function to automatically generate

public static Class1 operator +(Class1 one, Class1 two)


   throw new System.NotImplementedException();


Here’s the snippet to make the operator declaration used above:

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

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">

  <CodeSnippet Format="1.0.0">


<Title>Addition operator</Title>


<Description>Code snippet to create an addition operator for a class</Description>

<Author>Microsoft Corporation</Author>







<Literal Editable="false">




<Literal Editable="false">





<Code Language="csharp"><![CDATA[

public static $EnclosingClass$ operator +($EnclosingClass$ first, $EnclosingClass$ second)


throw new $NotImplementedException$("Method not yet implemented");






Tags: VSTips
Suggest a Tip!