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

Why read/write properties for XmlSerialization

Hello,

I have a question about XmlSerialization. I have a class with a private
field called createDate of the type DateTime. In the constructor of my class
I use DateTime. Now to create a timestamp that is assigned to the field
createDate. Because I want to encapsulate as much as possible of my class
data and don't want clients of my class to change the createDate but only
read it, I encapsulate the createDate field with a get Property. Now I want
this class to be the return type of a WebService I created and I want
consumers of my WebService to be able to read the createDate from the Xml
response from the WebService, so I added the XmlElementAttribute attribute to
my CreateDate property. The problem I run into is described on MSDN for the
XmlElementAttribute:

"Apply the XmlElementAttribute to public fields or public read/write
properties to control characteristics of the XML elements such as the element
name and namespace."

So, either the field needs to be public or my property needs to be a
read/write property. I think public fields are a bad practice in general, and
by adding a set method to my CreateDate property, I am opening up my class
more than I want to: clients of my class are now able to set the CreateDate
which I do not want them to be able to.

I hope you understand my problem here. Why should the XmlElementAttribute be
applied to read/write properties only and not to read properties? And what is
the best practice for this situation? I do want the createDate to be in the
Xml result of my WebService, but I don't want clients of my class to be able
to set the createDate.
Mar 8 '06 #1
0 965

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

Similar topics

2
by: Amith | last post by:
Hi, I am using an ActiveX created using delphi. It has a font property exposed. The font property is of type IFontDisp in the server(delphi). The font properties like Size, Bold, Underline etc...
2
by: Cory Burkhardt | last post by:
I am not sure what the suggested practice is for returning reference types from read-only properties. Consider an example: Suppose I have a Point class that is a reference type. I use the Point...
12
by: Jens Thiel | last post by:
Hi, is there a reason for C# to require attribute arguments (properties) to be read-write while VB and C++ are happy with only a setter? Simplified Example: public sealed class FooAttribute...
4
by: Markus Brenner | last post by:
Hi there! Hope anybody can help. I want to at least read (maybe write) the extended file properties of office documents like winword, excel, .... I've tried two ways till now, one by opening...
6
by: BBM | last post by:
I have an object that has a fairly complex construction sequence, so I have written a dedicated "factory" class that invokes the constructor of my object class (which does nothing but instantiate...
0
by: A programmer desperatly needing help! | last post by:
I use the xmlserialization on asp.net pages and on previous machines it never gave a problem. But now i somethings get a: Timed out waiting for a program to execute. The command being executed was...
4
by: pfrisbie | last post by:
I am developing a Web Services interface with C# and our partner is using Java (Axis 1.1). They require me to include xsi:types in the SOAP Messages I send them. For example: <Partner...
3
by: LW | last post by:
Hi! I am getting the following error message for my fairly simple web service. I have classes and have two DataSets that reference the same classes. The error is: The XML element named...
1
by: Frank | last post by:
Hi, Let's say I have a file named myFile.xml Within that file I have blocks of data which I'd like to add at different times during the day. e.g. <LogEntry>
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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...

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.