Adding Default Namespaces

Provided by the FMS Development Team

I like to have a lot of assertions in my code, to help me with my assumptions. So I am a heavy user of the System.Diagnostics namespace. What I feel painful though, is the typing of System.Diagnostics.Debug.Assert(). No problem, I thought, I could just use a using statement. After creating a lot of classes, I started wondering why I cannot insert a using System.Diagnostics similar to how Visual Studio inserts a using System for C# classes.

Explanation

Visual Studio handles this by using a template file. When a class file is added, it is done so by looking up a template on disk. That means, yes, we can add our own custom templates resulting in custom classes, reducing the drudgery of coding business layers. However, for the simple needs of this tip, we need to just add a using statement.

Steps

For the C# language:

  1. Navigate to the folder C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\VC#Wizards\CSharpAddClassWiz\Templates\1033. This may be different if you have installed to a drive other than C:.
  2. Edit the NewCSharpFile.cs.
  3. Add using System.Diagnostics;
  4. Save and close the file.

For the VB language:

  1. Navigate to the folder C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards\Class\Templates\1033. This may be different if you have installed to a drive other than C:.
  2. Edit the Class.vb.
  3. Add Imports System.Diagnostics
  4. Save and close the file.

Now return to Visual Studio and insert a new class and notice how it inserts the using or imports statement in the new file by default.

Return to Tips & Techniques Page

Additional Resources

 

 

Thank you! Thank you! I just finished reading this document, which was part of a link in the recent Buzz newsletter. I have printed it for others to read, especially those skeptical on the powers of Access and its capabilities.

Darren D.


View all FMS products for Microsoft Access All Our Microsoft Access Products

 

 

Free Product Catalog from FMS