I need to serialize into an XML file a hashtable.
From MSDN at XmlSerializer: http://msdn.microsoft.com/library/de...classtopic.asp
I implemented the indexable property and the add function but I'm still
getting the following exception:"The type System.Collecti ons.Hashtable
is not supported because it implements IDictionary."
My code for Item and Add add-on looks like this: -
[Serializable]
-
public class DaysArchive
-
{
-
-
public class HashTableItems
-
{
-
private IDictionaryEnumerator HashEntries;
-
public HashTableItems()
-
{
-
}
-
-
public void Initialize(Hashtable table)
-
{
-
HashEntries = table.GetEnumerator();
-
}
-
-
public System.Collections.DictionaryEntry this[string key]
-
{
-
get
-
{
-
HashEntries.Reset();
-
HashEntries.MoveNext();
-
while ((string)HashEntries.Key != key)
-
{
-
HashEntries.MoveNext();
-
}
-
return new DictionaryEntry(HashEntries.Key,HashEntries.Value);
-
}
-
}
-
}
-
-
public readonly HashTableItems Item;
-
public Hashtable archive;
-
-
public DaysArchive()
-
{
-
archive = new Hashtable();
-
this.Item = new HashTableItems();
-
this.Item.Initialize(archive);
-
}
-
-
public void AddItem(string Name, bool offline)
-
{
-
if (archive.ContainsKey(Name) == false)
-
archive.Add(Name,offline);
-
}
-
-
public bool GetKeyValue(string Name)
-
{
-
if (archive.ContainsKey(Name) == false)
-
throw new Exception("Key could not be found!");
-
-
IDictionaryEnumerator days_enum = archive.GetEnumerator();
-
-
-
days_enum.MoveNext();
-
while (((string)days_enum.Key != Name)&&(days_enum.MoveNext()));
-
-
return (bool)days_enum.Value;
-
}
-
-
public bool IsKeyInCollection(string Name)
-
{
-
return archive.ContainsKey(Name);
-
}
-
-
public void Add(System.Collections.DictionaryEntry cel)
-
{
-
archive.Add(cel.Key,cel.Value);
-
}
-
}
-
5 2514
Hi Victor,
I am probably missing something, what do you use HashTableItems for ?
What is the role of this part of the code :
HashEntries.Res et();
HashEntries.Mov eNext();
while ((string)HashEn tries.Key != key)
{
HashEntries.Mov eNext();
}
Are you trying to check the existence of a key ? Such type of
functionality is implemented by a Hashtable.
What is the role of DaysArchive ? Do you want to store (Name,
offline) pairs ? A Hashtable should be sufficient for this type of
functionality.
Please feel free to contact me if you need any more information.
Regards,
Bart http://www.xenopz.com/blog/bartdeboeck/
Hi Bart,
HashTableItems is a custom made class which I use to define the suport
for the Item indexed property. I make an instance of this class and I
return it in the get method of the Item property.
My goal is to serialize the Hashtable into an XML file. I you try to
serialize a hashtable the XmlSerializer throws an exception that says
Hashtable impelements IDictionary. Now I wrote my own class which has
an internal Hashtable. In the hash I store a string wich is the name of
a file and a boolean variable which represents the state of the file
data (if it was obtain from a the realtime-market or tha data was
aquired when the market was offline)
I modiffied the implementation of the whole DaysArchive class as follows
but I still get an exception that says "You must implement the default
accessor for DaysArchive because it inherits ICollection"
I still have not a clue what am I supposed to do next.
Thank you very much for your support.
Hi Victor,
Thanks for the extra info. I'll take a look at your question with the
extra info tomorrow.
cu,
Bart http://www.xenopz.com/blog/bartdeboeck/
Victor Paraschiv schreef: Hi Bart,
HashTableItems is a custom made class which I use to define the suport for the Item indexed property. I make an instance of this class and I return it in the get method of the Item property.
My goal is to serialize the Hashtable into an XML file. I you try to serialize a hashtable the XmlSerializer throws an exception that says Hashtable impelements IDictionary. Now I wrote my own class which has an internal Hashtable. In the hash I store a string wich is the name of a file and a boolean variable which represents the state of the file data (if it was obtain from a the realtime-market or tha data was aquired when the market was offline) I modiffied the implementation of the whole DaysArchive class as follows but I still get an exception that says "You must implement the default accessor for DaysArchive because it inherits ICollection" I still have not a clue what am I supposed to do next.
Thank you very much for your support. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Earl Teigrob |
last post by:
I am considering writing a Class that Selects, Adds, Updates and Deletes
Nodes in an XML File but do not what to reinvent the wheel. (See XML file
below)
That data format would emulate records in a Database Table with a Primary
Key for each Record (see xml sample below) and a flat file structure. I
would use a class to manipulate this type of data structure extensivly if I
had one.
Does anyone know of such an animal?
|
by: Don McNamara |
last post by:
Hi,
I've hit quite a strange problem with XmlSerializer on my W2K3 server. When
I serialize/deserialize using an exe on my local computer (XP), everything
works fine. When I put the code out on the server (W2K3) it throws an
exception. It only seems to happen when serializing/deserializing _arrays_
of a type. If I just serialize/deserialize one instance, it works fine.
The exception I get is: (sorry for the word wrapping.)...
|
by: Kenneth Baltrinic |
last post by:
Is the following code correct for serializing a quasi-single class, that is
a class that has a descreet (though more than one, so not a true singleton)
number of static instances and no dynamically creatable instances? Please
forgive my use of terms. Quasi-signleton is a term I made up and static
instances is a little bogus too but I don't know the correct terms for what
I mean if there are any. However, I think the code below should be...
|
by: hoopsho |
last post by:
Hi Everyone,
I am trying to write a program that does a few things very fast
and with efficient use of memory...
a) I need to parse a space-delimited file that is really large,
upwards fo a million lines.
b) I need to store the contents into a unique hash.
c) I need to then sort the data on a specific field.
d) I need to pull out certain fields and report them to the user.
|
by: MioTheGreat |
last post by:
I know how to take a single hashtable, and then use a binaryformatter
and a filestream to dump it to a file, but I need to serialize and
deserialize a hashtable inside a class. I've been trying this:
public Hashtable Directions;
public byte DirectionsSerialized
{
get
| |
by: Leszek Taratuta |
last post by:
Hello,
I have several drop-down lists on my ASP.NET page. I need to keep data
sources of these lists in Session State.
What would be the most effective method to serialize this kind of data
structures?
Thanks for any hints,
Leszek Taratuta
|
by: Doug Eller |
last post by:
I am serializing datasets and sending them out to a client application via a
web service. My problem is that the associated schema includes all of my
connection string, database username and password and SQL info. This is bad.
I can think of two ways to deal with this:
1. Parse the data out of the schema before i send it out
2. Encrypt the data
My question is......is there a better way?
|
by: JackRazz |
last post by:
I'm trying to serialize a collection to a file stream by serializing each object
individually. The code below works fine with the BinaryFormatter, but the
SoapFormatter reads the first object and just goes to the end of the file. After
reading the first object, the fStream.Position is pointed to the end of the file.
The collection serializes/deserilizes fine when I just serialize the hashtable vs.
each object in the hashtable.
Does...
|
by: Michael Maercker |
last post by:
Hi! I'm about to go nuts over my serializing problem.
This is my situation:
I have a Data-Class that can have children of the same class which are
stored in a hashtable, i.e:
X has A as a child
A has B as a child
When an object is changed it raises an Updated-Event which the
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |