Ever want to create an Interface in its own file? Ever notice there isn't a template in the new items (Ctrl+N) to add to a project? Well I have noticed and I think it is sort of dumb to have to create a new class then change the word "class" to "interface" - kinda of a waste of time (like using the mouse vs. useing keyboard short cuts). Funny side note is in VB you have to change both “Class“ and End “Class“ - more work than C#.
Yesterday on the train I looked into it a little further. Come to find out there is a Project.AddInterface command ... but VB doesn't support it and I couldn't get it to work in C# either (go ahead and try it -> Ctrl+Alt+A and type Project.AddInterface) ... so I came up with sort of a hack (which I fully plan on completing later - you know so it asks what name and all that). Here is what I did:
- Create the C# file that I want to use as a template (figure 1) - name InterfaceCS.cs
- Create the VB file I want to use as a template (figure 2) - name InterfaceVB.vb
- Save them both under "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE\NewFileItems"
1 ///<summary>
2 /// Description of the interface
3 ///</summary>
4 public interface I
5 {
6
7 }
Figure 1
1 '''<summary>
2 ''' Description of the interface
3 '''</summary>
4 Public Interface I
5
6 End Interface
Figure 2
Now when I press Ctrl+N I have 2 new items InterfaceVB and InterfaceCS, so no more changing "class" to "interface"
BTW: I also took the opportunity to update my xsltfile.xslt to the xml in Figure 3. If you do any templates you know that typing that stuff is a waste of time (you should also have the xslt.xsd in your schemas directory too).
8 <?xml version="1.0" encoding="UTF-8" ?>
9 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">
10 <xsl:template match="/">
11 <!-- Start Template here -->
12 </xsl:template>
13 </xsl:stylesheet>
Figure 3