Since the XmlReader object and the MyStrings object in your code share the
same nametable you can use a object reference comparison instead of String
comparison.
Something like,
if (( (object)reader.LocalName ) == ( (object)strings.stringA )) return new
ClassA();
Thanks
Srikanth.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Colin Savage" <sav912@hotmail.com> wrote in message
news:bm5s86$n1t$1@ctb-nnrp2.saix.net...[color=blue]
> I am trying to work out the best way to use the NameTable class in my C#
> application.
>
> I am assuming that getting/adding a string to the nametable has the same
> overheads as comparing a string normally, so I have created a class which
> holds references to the atomized strings.
> Is there a better way to do this? simple example below
>
> //Class to provide "string constants"
> private class MyStrings
> {
> public String stringA;
> public String stringB;
>
> public MyStrings(NameTable nt)
> {
> stringA = nt.Add("A");
> stringB = nt.Add("B");
> }
> }
>
> //Class to do the work
> public class MyAppClass
> {
> private MyStrings myStrings;
>
> //assume strings was created once somewhere else
> public MyAppClass(MyStrings strings)
> {
> myStrings = strings
> }
>
> public object factoryMethod(XmlReader reader)
> {
> //reader was created using the same NameTable used with MyStrings
> if (reader.LocalName == strings.stringA) return new ClassA();
> if (reader.LocalName == strings.stringB) return new ClassB();
>
> }
>
> Thanks
> Colin
>
>[/color]