473,378 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Another NameTable Question

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
Nov 11 '05 #1
3 1308
Colin Savage wrote:
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

Looks as the best as possible to me. Preloaded atomized string and
reader built on the same NameTable - I believe nothing more can be done.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2
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" <sa****@hotmail.com> wrote in message
news:bm**********@ctb-nnrp2.saix.net...
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

Nov 11 '05 #3
SQL Server Development Team [MSFT] wrote:
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();


Which is exactly the same as
if (reader.LocalName == strings.stringA ) return new ClassA();

because the first thing String comparison does is above object comparison.
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I...
2
by: Maitre Bart | last post by:
What I want to perform is calling a member function of container 1 (CRunner), using as argument the value of a container 2 (CNames). The purpose is to transfer values from C2 into C1 using a...
4
by: Colin Savage | last post by:
In my C# application I have an object model which can be loaded and saved into xml, not using serialization. When changes are made to the object model by the user interface, I use another thread to...
2
by: Mark Bosley | last post by:
There seems to be little interest in this object, the docs are wrong and it doesn't do much. Two years ago, it was pointed out that the documentation is nonsensical...
2
by: PerryC | last post by:
Scenario: FormA: Field1, Field2 (Field1 is a combo box based on a NameTable w/ Name and phone fields) When users choose Field1 with Name1 (in record1 of NameTable), Field2 will...
0
by: Sebastian Hiller | last post by:
Hello, i'm new to .Net (i'm using VB as language and i'm working in the code-behind mode) and i can't solve the following problem: I have a WebForm and want to Add a UserControl...
0
by: Fratt | last post by:
I have an xml document defined by a schema that includes roughtly 1100 types. When I go to deserialize the root type I notice that the xmlSerializer creates the nametable and adds all 1100 types...
5
by: Alexander Gnauck | last post by:
Hello, is there a way to disable or reset the entries in a NameTable? Background is that is that i create small XmlElements and send them over the wire with a TCP connection. I can't create...
4
by: MichaelK | last post by:
Hello. I have all data already collected on the current page? I want to open another window with the form, fill the fields and submit that form. So basically the question is how can I fill all...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.