Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Go to your default C# code snippets location, usually in <em>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC#\Snippets\1033\Visual C#</em> and make a copy of <em>ctor.snippet</em> into your personal code snippets location, rename it, and give it a proper name and shortcut key. Then change the declaration (look at other existing ones), something like the below can do the job. Once you create it, you can simply type <code>svc + TAB</code> (or whatever shortcut you choose then tab) in an empty class file, and you should get the content filled up, alternatively you may be able to customize a class template so when you do add new, you can select your new template.</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"&gt; &lt;CodeSnippet Format="1.0.0"&gt; &lt;Header&gt; &lt;Title&gt;Some Constructor&lt;/Title&gt; &lt;Shortcut&gt;svc&lt;/Shortcut&gt; &lt;Description&gt;my description&lt;/Description&gt; &lt;Author&gt;Jason was here&lt;/Author&gt; &lt;SnippetTypes&gt; &lt;SnippetType&gt;Expansion&lt;/SnippetType&gt; &lt;/SnippetTypes&gt; &lt;/Header&gt; &lt;Snippet&gt; &lt;Declarations&gt; &lt;Literal&gt; &lt;ID&gt;accessor&lt;/ID&gt; &lt;ToolTip&gt;Access modifier&lt;/ToolTip&gt; &lt;Default&gt;public&lt;/Default&gt; &lt;/Literal&gt; &lt;Literal Editable="false"&gt; &lt;ID&gt;classname&lt;/ID&gt; &lt;ToolTip&gt;Class name&lt;/ToolTip&gt; &lt;Function&gt;ClassName()&lt;/Function&gt; &lt;Default&gt;ClassNamePlaceholder&lt;/Default&gt; &lt;/Literal&gt; &lt;Literal Editable="true"&gt; &lt;ID&gt;svcA&lt;/ID&gt; &lt;ToolTip&gt;Service A&lt;/ToolTip&gt; &lt;Default&gt;ServiceA&lt;/Default&gt; &lt;/Literal&gt; &lt;Literal Editable="true"&gt; &lt;ID&gt;svcAvar&lt;/ID&gt; &lt;ToolTip&gt;Service A&lt;/ToolTip&gt; &lt;Default&gt;serviceA&lt;/Default&gt; &lt;/Literal&gt; &lt;Literal Editable="true"&gt; &lt;ID&gt;svcB&lt;/ID&gt; &lt;ToolTip&gt;Service B&lt;/ToolTip&gt; &lt;Default&gt;ServiceB&lt;/Default&gt; &lt;/Literal&gt; &lt;Literal Editable="true"&gt; &lt;ID&gt;svcBvar&lt;/ID&gt; &lt;ToolTip&gt;Service B&lt;/ToolTip&gt; &lt;Default&gt;serviceB&lt;/Default&gt; &lt;/Literal&gt; &lt;/Declarations&gt; &lt;Code Language="csharp"&gt;&lt;![CDATA[readonly $svcA$ $svcAvar$; readonly $svcB$ $svcBvar$; $accessor$ $classname$ ($svcA$ serviceA, $svcB$ serviceB) { this.$svcAvar$ = serviceA; this.$svcBvar$ = serviceB }$end$]]&gt; &lt;/Code&gt; &lt;/Snippet&gt; &lt;/CodeSnippet&gt; &lt;/CodeSnippets&gt; </code></pre> <p>In the above we declare variables for the classes <code>svcA = ServiceA</code>, <code>svcB = ServiceB</code>, and the class variables <code>svcAvar = serviceA</code> and <code>svcBvar = serviceB</code>, so we can easily modify in one location, you can create more for the params in the constructor, etc, but should be enough to get you started.</p> <p>Regarding the variable number of params, you can use the default params literal which would then let you type whatever params you need after you insert the ctor, if you have varying class level variables, then just like others have said, create several snippets with different shortcuts, like <strong>svc</strong>, <strong>svc1</strong>, <strong>svc2</strong>, <strong>svc3</strong> etc</p> <pre><code>&lt;Literal&gt; &lt;ID&gt;params&lt;/ID&gt; &lt;ToolTip&gt;Parameter list&lt;/ToolTip&gt; &lt;Default&gt;&lt;/Default&gt; &lt;/Literal&gt; </code></pre> <p>then <code>...&lt;![CDATA[$accessor$ $classname$ (...$params$)</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload