zondag, september 24, 2006

 

VS2005 - template versus snippets

I'm using codesnippets a lot, also for instant building of our own custom classes (inheritance, bunch of overloads and methods) Now I remembered that it is also possible to create custom templates. For class templates this is a bit more faster because by selecting your custom template (add new item...) you can modify your template so it will fill in the namespace and class name automatically.

Summary:
Class structure - > use templates
properties/methods -> use snippets


Possible parameters (put into your template like this: $myparam$)
itemname
The user-provided name from the dialog. This value is often used for naming classes and files.
safeitemname
The same as itemname but with all unsafe characters removed.
safeitemrootname
The name of the root item, which can be used for multi-item templates. For example, if you have partial classes, or a code-beside or code-behind scenario, you can use this item in the secondary files when you need the safeitemname of the main item being created.
projectname
The user-provided name of the project for a project template.
safeprojectname
The user-provided name of the project for a project template with all unsafe characters removed.
rootnamespace
The root namespace of the project for an item template, which can be used to replace the namespace in a project item source file.
guid[1-10]
A GUID that can be used as a unique identifier for uses such as project GUID in the project file. You can specify up to 10 different GUID parameters using the syntax: guidx, where x is a number between 1 and 10.
time
The current time in the format DD/MM/YYYY HH:MM:SS.
year
The current four-digit year.
username
The Windows username of the logged-in user.
userdomain
The Windows domain of the logged-in user.
machinename
The name of the machine where the template is being used.
clrversion
The version of the common language runtime being used.
registered-organization
The registered organization of the user based on the system settings.
wizarddata
A single string that can be any XML or string data included in the WizardData element in a template metadata file.

how to refs:
http://codebetter.com/blogs/david.hayden/archive/2005/11/06/134343.aspx
http://msdn.microsoft.com/msdnmag/issues/06/01/CodeTemplates/