Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / XML

Creating project item code templates for Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
4.86/5 (47 votes)
26 Jul 200517 min read 185.9K   2.5K   142  
This article describes how new project item code templates work in Visual Studio .NET 2003 (and 2005) and presents a component that makes it easy to write new templates.
[%
<wizard>
	<page>
		<title>Select data type for the keys</title>
		<description>Select data type for the key values of the dictionary</description>
		<variable name="key_datatype"/>
	</page>	
	<page>
		<title>Select data type for the values</title>
		<description>Select data type for the values of the dictionary</description>
		<variable name="value_datatype"/>
	</page>	
</wizard>
%]Imports System
Imports System.Collections

Public Class [%<variable type="standard" name="filenamebase"/>%]
   Inherits DictionaryBase

   Default Public Property Item(key As [%<variable type="custom" name="key_datatype"/>%]) As [%<variable type="custom" name="value_datatype"/>%]
      Get
         Return CType(Dictionary(key), [%<variable type="custom" name="value_datatype"/>%])
      End Get
      Set
         Dictionary(key) = value
      End Set
   End Property

   Public ReadOnly Property Keys() As ICollection
      Get
         Return Dictionary.Keys
      End Get
   End Property

   Public ReadOnly Property Values() As ICollection
      Get
         Return Dictionary.Values
      End Get
   End Property

   Public Sub Add(key As [%<variable type="custom" name="key_datatype"/>%], value As [%<variable type="custom" name="value_datatype"/>%])
      Dictionary.Add(key, value)
   End Sub 'Add

   Public Function Contains(key As [%<variable type="custom" name="key_datatype"/>%]) As Boolean
      Return Dictionary.Contains(key)
   End Function 'Contains

   Public Sub Remove(key As [%<variable type="custom" name="key_datatype"/>%])
      Dictionary.Remove(key)
   End Sub 'Remove

End Class '[%<variable type="standard" name="filenamebase"/>%]

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Sweden Sweden
Worked in the industry since 1996, as a developer, architect, project leader, etc.

Current interests include DirectX, Visual Studio adaptation (add-ins, macros, etc), C# and C++.

Comments and Discussions