Hi Group,
I've defined a class with an 'ID' property, which is a GUID that is created
at the time of the very first object instance creation. This member is not
included when I serialize an object instance to XML, since it is read-only.
Actually, I want to preserve the ID value with serialization/deserialization
processes but I do *not* want it to be writeable from code by a simple
myObject.ID = ... assignment - how to achieve this?
As far as I can see, I have to write my own serialization/deserialization
routines for this purpose. Does anyone know a less laborious way to get what
I want here, e.g. by a certain ["AttributeLabel"] for XML serialization that
I don't know yet?
Thanks for your help,
greetings
Hans 5 2513
"Hans-J?rgen Philippi" <HJ********@aol.comwrote:
Hi Group,
I've defined a class with an 'ID' property, which is a GUID that is created
at the time of the very first object instance creation. This member is not
included when I serialize an object instance to XML, since it is read-only.
Actually, I want to preserve the ID value with serialization/deserialization
processes but I do *not* want it to be writeable from code by a simple
myObject.ID = ... assignment - how to achieve this?
As far as I can see, I have to write my own serialization/deserialization
routines for this purpose. Does anyone know a less laborious way to get what
I want here, e.g. by a certain ["AttributeLabel"] for XML serialization that
I don't know yet?
There needs to be a "setter" on there because when the class is again
deserialized, it has to set the value back to the object. XML serialization
does not work the same as the native .NET serialization, as it goes against
properties rather than instance variables. I find this rather annoying as
well. In short, I believe you need to roll your own.
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Hans,
Assuming that the field internally is not read only (just the property
is), you could achieve what you want by implementing IXmlSerializable. The
XmlSerializer will call this interface to serialize and deserialize your
class. Basically, you would output the id tag, and then set it internally
when your instance is dehydrated.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Hans-Jürgen Philippi" <HJ********@aol.comwrote in message
news:uk**************@TK2MSFTNGP05.phx.gbl...
Hi Group,
I've defined a class with an 'ID' property, which is a GUID that is
created at the time of the very first object instance creation. This
member is not included when I serialize an object instance to XML, since
it is read-only.
Actually, I want to preserve the ID value with
serialization/deserialization processes but I do *not* want it to be
writeable from code by a simple myObject.ID = ... assignment - how to
achieve this?
As far as I can see, I have to write my own serialization/deserialization
routines for this purpose. Does anyone know a less laborious way to get
what I want here, e.g. by a certain ["AttributeLabel"] for XML
serialization that I don't know yet?
Thanks for your help,
greetings
Hans
Thomas,
Not really, you can always implement IXmlSerializable and then you can
put any values you want in the output stream, as well as read them back in
when you rehydrate your object.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Thomas T. Veldhouse" <ve*****@yahoo.comwrote in message
news:3P******************************@giganews.com ...
"Hans-J?rgen Philippi" <HJ********@aol.comwrote:
>Hi Group,
I've defined a class with an 'ID' property, which is a GUID that is created at the time of the very first object instance creation. This member is not included when I serialize an object instance to XML, since it is read-only. Actually, I want to preserve the ID value with serialization/deserialization processes but I do *not* want it to be writeable from code by a simple myObject.ID = ... assignment - how to achieve this?
As far as I can see, I have to write my own serialization/deserialization routines for this purpose. Does anyone know a less laborious way to get what I want here, e.g. by a certain ["AttributeLabel"] for XML serialization that I don't know yet?
There needs to be a "setter" on there because when the class is again
deserialized, it has to set the value back to the object. XML
serialization
does not work the same as the native .NET serialization, as it goes
against
properties rather than instance variables. I find this rather annoying as
well. In short, I believe you need to roll your own.
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.comwrote:
Thomas,
Not really, you can always implement IXmlSerializable and then you can
put any values you want in the output stream, as well as read them back in
when you rehydrate your object.
Oh, yes indeed. I am not sure why that didn't occur to me. One thing I can
say is that it is very tedious to do that [and ISerializable] if you have a
large object graph.
--
Thomas T. Veldhouse
Key Fingerprint: 2DB9 813F F510 82C2 E1AE 34D0 D69D 1EDC D5EC AED1
Hi Nicholas,
Assuming that the field internally is not read only (just the property
is), you could achieve what you want by implementing IXmlSerializable.
The XmlSerializer will call this interface to serialize and deserialize
your class. Basically, you would output the id tag, and then set it
internally when your instance is dehydrated.
Yes, you're right, the private ID string is writeable without having a set
{...} part in its related public property code.
The point is: If I implement the IXmlSerializable interface, I end up
writing the complete serialization/deserialization code on my own, right?
And this is what I didn't want in my large class with a lot of members...
Maybe there's a way to interact with the intrinsic XML serialization for a
certain field only? That's what I was looking for.
Thanks anyway,
Hans This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andreas Palsgård |
last post by:
Hey.. i want to write a class object containing both strings and integers,
to a file on disk, and be able to read it properly again at another time. I
made the code below... it doesn't work, but...
|
by: Philip Reed |
last post by:
I'm trying to write a preferences-handling infrastructure that
serializes prefs to XML. Basically I want to read in a common
"default" prefs set, then read in the user's prefs and override the...
|
by: Philip K |
last post by:
I was trying to use Soap serialisation to save some systems settings
how ever it fails if the settings contain a Font object, works fine if
the Font object is not in the object being serialised.
...
|
by: films |
last post by:
I understand the concept.
Serialization of a class will add all the sub-objects of the class to
the stream if there are also serializible.
So say I have:
class Author
{
|
by: Matthew |
last post by:
I have a nice little Sub that saves data in a class "mySettings" to an XML
file.
I call it like so:
Dim mySettings As mySettings = New mySettings
mySettings.value1 = "someText"
mySettings.value2...
|
by: DazedAndConfused |
last post by:
I encryted a serialized binary formatted object. Now I can't figure out how
to deserialize it so that I can decrypt it.
I used this code encrypt and write it out:
Dim fe As New...
|
by: J. Askey |
last post by:
I am implementing a web service and thought it may be a good idea to return a
more complex class (which I have called 'ServiceResponse') in order to wrap
the original return value along with two...
|
by: Thomas S |
last post by:
Any suggestions on how to deserialize an object from one line of XML?
I'm trying to deserialize multiple objects from one XML document, each
object on one line of the file. The serialization is...
|
by: mkvenkit.vc |
last post by:
Hello,
I hope this is the right place to post a question on Boost. If not,
please let me know where I can post this message and I will do so.
I am having a strange problem with std::string as...
|
by: David Thielen |
last post by:
Hi;
I have a small XML file that I need to read/change from my app. Is
there some easy way to map from XML to my objects so I can just read
it in to my objects, change the objects as needed,...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
| |