473,395 Members | 1,763 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,395 software developers and data experts.

Serialization of Enums

I'm a bit stumped on some odd behaviour I've found when serializing a class
that has both Enumeration and Object fields.

My class is as follows:

Public Class TestClass
Public Value1 As Object
Public Value2 As Microsoft.Win32.RegistryHive
End Class

and if I serialize the following object:

Dim objTestObject As New TestClass
objTestObject.Value1 = Microsoft.Win32.RegistryHive.LocalMachine
objTestObject.Value2 = Microsoft.Win32.RegistryHive.ClassesRoot

I get this xml out, which is what I expected:

<?xml version="1.0" encoding="utf-8"?>
<TestClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Value1 xsi:type="RegistryHive">LocalMachine</Value1>
<Value2>ClassesRoot</Value2>
</TestClass>

*However*, if I add a remove the Value2 field definition from the class so
that it reads:

Public Class TestClass
Public Value1 As Object
End Class

then Value1 ceases to be of xsi:type="RegistryHive" and I get this ixml
nstead:

<?xml version="1.0" encoding="utf-8"?>
<TestClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Value1 xsi:type="xsd:int">-2147483646</Value1>
</TestClass>

when what I really want is:

<?xml version="1.0" encoding="utf-8"?>
<TestClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Value1 xsi:type="RegistryHive">LocalMachine</Value1>
</TestClass>

Does anyone know how to rig the XML serialization attributes on TestClass so
that it still serializes Value1 as "<Value1
xsi:type="RegistryHive">LocalMachine</Value1>" even if the Value2 field is
absent from the class definition? Bearing in mind that Value1 still needs to
be an Object field.

Many thanks in advance,

Mike

Nov 12 '05 #1
0 918

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

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
0
by: vitaleaf | last post by:
I have discovered the following problem. I have an enumeration defined in a schema which has the values 1,2,3,4,5 defined for serialization purposes (what xmlserializationwriter uses). In the...
3
by: Picho | last post by:
Hi all. Trying to serialize and desirialize an object. the object is transfered as a byte using a web service to the client. the client then has to deserialize the byte to an object and work...
6
by: Polo | last post by:
Hi, I have two public enums types each defined in a class (PolarDiagram and KDiagram) in a namespace (RTech.Graphic) I try to serialize this class with XmlSerializer without success A...
0
by: student | last post by:
In Summary: Create an object - dont set one of its Enum Type properties and make sure it does not appear in XML Object Serialization. Strings function as hoped for but Enums do not Heres my...
3
by: Diego | last post by:
I have an Enum like this: public enum DAYS { Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6,
0
by: jsmith72 | last post by:
Can some Please tell me why the following collection is not XML Serializable: Imports System.Xml Imports System.Runtime.Serialization Namespace MyNamespace <Serializable()Public Class...
8
by: Gonza | last post by:
Hi group, i'm getting the following excepction while trying to serialize a class: Types 'NYC.TrueFinance.BusinessEntities.ExtendedBaseEntityTypeData.EntityTypes' and...
2
by: sylvain.ross | last post by:
Hello everybody, I have a very weird problem regarding the serialization of a class that I wrote (named DummyClass in my exemple). My class inherits from DataTable. Then I just try a dummy...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.