Pre-loaded Xml NameTable Codesmith template

As a follow up to an earlier post I created a small Codesmith template to generate a pre-loaded NameTable (in C#) from a list of strings in a text file. The idea behind this is if you are going to be parsing an xml file that uses a known schema, then you can usually get a performance boost by making use of the NameTable for storing strings for comparisons. Because you know what all the strings that will be needed are, you can preload the nametable and have those strings available on the class as public members for comparison.

The generated class looks something like this

using System;
using System.Xml;

namespace MyNamespace
{
    
public class MyNameTable:NameTable
    {
        
public readonly String FOO;    
        
public readonly String BAR;    
        
public readonly String SOMEWIERDWORD;    
    
        
public MyNameTable()
        {
            FOO = 
this.Add("foo");    
            BAR = 
this.Add("bar");    
            SOMEWIERDWORD = 
this.Add("somewierd.word");    
        }
    }
}

Download the template here

powered by IMHO 1.2

Published Wednesday, June 01, 2005 9:52 AM by colin
Filed under:

Comments

No Comments