Content by Category
.NET 1.x
.NET 2.0
.NET 3.0
.NET 3.5
.NET 4.0
.NET Assemblies
.NET Framework
.NET Getting Started
Accessibility
ADO.NET
Advertorials
Agile Development
AJAX
Architecture
ASP.NET
ASP.NET MVC
ASP.NET WebForms
Azure
B2B (Business Integration)
Bing
BizTalk
Book Excerpts
Build and Deploy
C#
C++
ClickOnce
Cloud Computing
Code Contracts
CODE on the Road!
COM+
Community
Conferences
Continuous Integration
Crystal Reports
CSLA.NET
CSS
Data
Design Patterns
Development Process
Display Technologies
Distributed Computing
DotNetNuke
DSL
Dynamic Programming
Editorials
Enterprise Services ("COM+")
Entity Framework
Events
Expression Blend
F#
Fox to Fox
Frameworks
Functional Programming
Git
Graphics
Internet Explorer 8.0
Interviews
iPhone
Iron Ruby
Java
Java Script
jQuery
LINQ
Linux
Mac OS X
MDX
Microsoft Application Blocks
Microsoft Business Rules Framework
Microsoft Dynamics
Microsoft Expression
Microsoft Office
Mobile Development
Mobile PC
Mono
MsBuild
Network
NHibernate
Object Oriented Development
Odata
Open Source
Opinion
Opinions
Oracle
ORM
Other Languages
Parallel Programming
Patterns
Podcasts
Post Mortem
PowerPoint
Print/Output
Prism
Product News
Product Reviews
Project Management
Python
Q&A
Rails
Rake
Reporting Services
REST
RIA Services
Ruby
Ruby on Rails
Search
Security
Services
SharePoint
Silverlight
SOA
Social Networks
Software & Law
Software Business
Source Control
Speech-Enabled Applications
SQL Server
SQL Server 2000
SQL Server 2005
SQL Server 2008
SQL Server CE/AnyWhere/Mobile/Compact
SSIS
Subversion
Sync Framework
Tablet PC
TDD
Team System
Techniques
Testing and Quality Control
Tips
UI Design
UML
User Groups
VB Script
VB.NET
Version Control
VFP and .NET
VFP and SQL Server
Virtual Earth
Vista
Visual Basic
Visual Basic 6 (and older)
Visual FoxPro
Visual Studio .NET
Visual Studio 2005
Visual Studio 2008
Visual Studio 2010
Visual Studio Tools for Office
VSX
WCF
Web Development (general)
Web Services
WF
Whitepapers
Windows 7
Windows Azure
Windows Live
Windows Server
Windows Vista
WinForms
Workflow
WPF
XAML
XML
XNA
XSLT



Virtual Brown Bag Lunches


 


iPhone iPad Developers Conference

Reader rating:
Click here to read 6 comments about this article.
Article source: CoDe (2004 - November/December)


Article Pages:  1  2 3 4 - Next >


Maximize Your Productivity with Project Item Templates

You can create your own Windows Forms, Web Forms, or class templates to reuse code and maximize your productivity in Visual Studio 2003.

Code reuse has been a mantra of software development for decades. .NET provides for code reuse in many ways including inheritance, components, and of course the indispensable function. Visual Studio 2003 expands the concept of reuse by providing a set of editable built-in templates for any project items, such as Windows Forms, Web Forms, or classes. Or to fully gain productivity benefits, you can create your own templates and tailor them to your specific needs.

Editing a Built-In Template

A template is a pattern with a custom format that is used as a starting point for building applications. Visual Studio provides a set of built-in templates for forms, classes, and other project items. When you add a class to a project, for example, Visual Studio uses a class template to provide you with the starting point for the class.

"
You may find that each of the code files for your business objects contains a standard comment header, a common list of imports, a usual definition of regions, and a predefined set of interfaces or method signatures.
"

But often the built-in templates don't provide all of the functionality that you want. In Visual Studio, you can edit the built-in templates or create custom templates.

You can find the majority of the built-in templates in your \Program Files\Microsoft Visual Studio .NET 2003 directory. The VB templates are in the Vb7\VBWizards subdirectory and the C# templates are in the VC#\VC#Wizards subdirectory.

Each type of item, such as Windows Forms, Web Forms, and classes, has its own folder under the appropriate VBWizards or VC#Wizards subdirectory. You can navigate down to an existing template file to edit any of the built-in templates.

For example, to edit the standard class template for VB, navigate to \Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\Class\Templates\ 1033\Class.vb. Open this file and add any code or comments that you wish to include in the built-in template. A common change is to include Option Explicit On in the standard VB class template as follows:

Option Strict On

Public Class [!output SAFE_ITEM_NAME]
    
End Class

For C#, navigate to \Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\ CSharpAddClassWiz\Templates\1033\NewCSharpFile.cs. Open this file and add any code or comments that you wish to include in the template. A common change is to include additional type imports in the standard C# class template as follows:

using System;
using System.Diagnostics;

namespace [!output SAFE_NAMESPACE_NAME]
{
   /// <summary>
   /// Summary description for [!output 
   /// SAFE_CLASS_NAME].
   /// </summary>
   public class [!output SAFE_CLASS_NAME]
   {
      public [!output SAFE_CLASS_NAME]()
      {
         //
         // TODO: Add constructor logic here
         //
      }
   }
}

Notice the [!output SAFE_ITEM_NAME] syntax in both of these examples. The Visual Studio wizard uses these directives to substitute the name you provide when you add a project item using the Add New Item dialog box.

Once you have updated a template file, save it and give it a try. Open any exiting project or create a new project. Right-click on the project and select Add then choose Add Class from the context menu. Give the class a name and click OK. Visual Studio create the class file using your revised template. Notice that Visual Studio substitutes the class name you specified into the appropriate locations in the template as defined by the template directives.

&

By: Deborah Kurata

Deborah Kurata is cofounder of InStep Technologies Inc., a professional consulting firm that focuses on turning your business vision into reality using Microsoft .NET technologies. She has over 15 years of experience in architecting, designing and developing successful applications.

Deborah is the author of several books, including Best Kept Secrets in .NET (Apress), Doing Objects in Visual Basic 6.0 (SAMS) and Doing Web Development: Client-Side Techniques (Apress). She is on the INETA Speaker’s Bureau, is a well-known speaker at technical conferences, and is a Microsoft Most Valuable Professional (MVP). After a hard day of coding and taking care of her family, Deborah enjoys blowing stuff up (on her XBox of course).

Some of the information in this article was obtained from her upcoming book, Doing Objects in VB 2005.

deborahk@insteptech.com

Fast Facts

Templates allow you to define the structure and content of your project items and reuse them each time you add an item to your project.



Article Pages:  1  2 3 4 - Next Page: 'Creating a Project Item Template' >>

Page 1: Maximize Your Productivity with Project Item Templates
Page 2: Creating a Project Item Template
Page 3: Step 5: Updating the VSDir File
Page 4: Customizing the Template File

How would you rate the quality of this article?
1 2 3 4 5
Poor      Outstanding

Tell us why you rated the content this way. (optional)

Average rating:
4 out of 5

32 people have rated this article.

      DevConnections

 

INSTANTLY dtSearch® TERABYTES OF TEXT