473,657 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xml serialize private properties with a wrapper class -- how to?


We're using XmlSerializer to serialize our data objects for
persistence in a WinForms app. This is our primary data store, we're
not web connected and are not using a database. We've had to program
some of our classes in undesired ways to support XmlSerializer and
it's limitations (public new constructor, only public properties, no
dictionary support, etc).

We just came across a note in one of the articles on XML Serialization
that says you can work around some of these issues with a wrapper
class, but there's no link for more info. What is this talking about
and how can we better support XmlSerializer based persistence without
having to mess with our object model?

We've also looked at using the SoapTypeImporte r which provided little
additional benefit and the SoapFormatter which created undesirable XML
(one of the main reasons for using XmlSerializer is to allow
interoperabilit y with other non .net apps and simple XML is a big
plus).

Thanks,

Sam
XML Serialization in the .NET Framework
http://msdn.microsoft.com/library/de...ml01202003.asp

Q: How can I serialize classes that were not designed for XML
serialization if I do not want to use the SoapFormatter?

A: You can design special wrapper classes that expose or hide fields
and properties from the XmlSerializer.

Nov 21 '05 #1
1 5637
Let's say you have

Public Class Customer
Protected Address as String
End Class

Address wouldn't serialize. But you could do:

Public Class CustomerSerial
Inherits Customer

Public Property AddressString
Get
Return Address
End Get
Set
Address = Value
End Set
End Property
End Class.

Now, you could do:

Dim c as New Customer
Dim s as CustomerSerial = c

s would serialize and deserialize just fine.

Hope this helps

- Scott Swigart
http://blog.swigartconsulting.com

"Samuel R. Neff" <sr********@spa mpleasespeakeas y.net> wrote in message
news:5n******** *************** *********@4ax.c om...

We're using XmlSerializer to serialize our data objects for
persistence in a WinForms app. This is our primary data store, we're
not web connected and are not using a database. We've had to program
some of our classes in undesired ways to support XmlSerializer and
it's limitations (public new constructor, only public properties, no
dictionary support, etc).

We just came across a note in one of the articles on XML Serialization
that says you can work around some of these issues with a wrapper
class, but there's no link for more info. What is this talking about
and how can we better support XmlSerializer based persistence without
having to mess with our object model?

We've also looked at using the SoapTypeImporte r which provided little
additional benefit and the SoapFormatter which created undesirable XML
(one of the main reasons for using XmlSerializer is to allow
interoperabilit y with other non .net apps and simple XML is a big
plus).

Thanks,

Sam
XML Serialization in the .NET Framework
http://msdn.microsoft.com/library/de...ml01202003.asp

Q: How can I serialize classes that were not designed for XML
serialization if I do not want to use the SoapFormatter?

A: You can design special wrapper classes that expose or hide fields
and properties from the XmlSerializer.

Nov 21 '05 #2

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

Similar topics

4
2875
by: Christian Christmann | last post by:
Hi, I need an STL list and was thinking of putting the list in wrapper class. The reason for my decision is that you can much better perform consistency checks. For instance, I need a function to append a list to another. Using a wrapper class I could do something like:
10
7360
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
1
2153
by: sureshjram | last post by:
Hi all , What is a Wrapper Class in c#?? I am new to this OOPS plz explain it thanks in advance regards Suresh
2
2283
by: John Mullin | last post by:
We are having a problem which appears similar to a previous posting: http://groups.google.com/groups?hl=en&lr=&frame=right&th=d97f552e10f8c94c&seekm=OZw33z9EDHA.2312%40TK2MSFTNGP10.phx.gbl#link1 In the current release of our system, we decided to "wrap" the ASP.NET Session and Application objects to improve code clarity and accuracy. For example, instead of: Session = new SomeListClass;
2
1319
by: Vikram | last post by:
i want to serialize datagrid properties.. so that it can be retirved later from other form and similiar datagrid can be generated. How can it be done ?
0
1667
by: Behzad | last post by:
Hi, Iam trying to develope a program to show and manipulate SVG files.As many suggestions i tried to use Adobe SVG control.I used Aximp to produce a wrapper class for ASV and it produced 2 dll as MSDN says but when i added 2 produced .dll to my project and tried to use them i got the NullReferenceException exception.I put my code away and tried to use others code.But their code still had the same problem(i tried so many codes and...
2
1472
by: source_acct | last post by:
Can someone explain the function of a wrapper class and maybe an example? Thanks.
2
2870
by: Christian Chrismann | last post by:
Hi, an application uses a wrapper class for an STL list. Basically, this template class provides the same functions (delete, append, find...) as an ordinary STL list. Additionally, there are some convenient functions for iterating through the list. For instance, to go through all elements of the list (after fetching the first list element), the class provides a function that looks as follows:
2
3503
JnrJnr
by: JnrJnr | last post by:
I am creating a wrapper class that derives from the ApplicationSettingsBase class to programmatically create application settings for a windows form. I got it right to save my setting but now I want to know where is this "file" or ".config file" stored so I can view all the settings I have created. public class myUserSetting : ApplicationSettingsBase { // public String newDir { ...
0
8392
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, 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...
0
8305
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7321
agi2029
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...
0
5632
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();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4301
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1607
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.