473,395 Members | 2,006 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.

Serializing private members with public Propery getter doesn't wor

consider:

public class test
{
public string[] az;
public test()
{ az = new string[2]; az[0] = "0"; az[1] = "1";}
}

This will serialize just fine but:

public class test
{
private string[] az;
public string[] AZ
{
get { return az; }
}
public test()
{ az = new string[2]; az[0] = "0"; az[1] = "1";}
}

does not., no matter what Xml_xyz_Attribute tag I use either. Is this
possible?

Nov 16 '05 #1
3 1456
Are you using XMLSerializer or BinaryFormatter?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"punkbot" <pu*****@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
consider:

public class test
{
public string[] az;
public test()
{ az = new string[2]; az[0] = "0"; az[1] = "1";}
}

This will serialize just fine but:

public class test
{
private string[] az;
public string[] AZ
{
get { return az; }
}
public test()
{ az = new string[2]; az[0] = "0"; az[1] = "1";}
}

does not., no matter what Xml_xyz_Attribute tag I use either. Is this
possible?

Nov 16 '05 #2
XMLSerializer

"Sahil Malik" wrote:
Are you using XMLSerializer or BinaryFormatter?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"punkbot" <pu*****@discussions.microsoft.com> wrote in message
news:AE**********************************@microsof t.com...
consider:

public class test
{
public string[] az;
public test()
{ az = new string[2]; az[0] = "0"; az[1] = "1";}
}

This will serialize just fine but:

public class test
{
private string[] az;
public string[] AZ
{
get { return az; }
}
public test()
{ az = new string[2]; az[0] = "0"; az[1] = "1";}
}

does not., no matter what Xml_xyz_Attribute tag I use either. Is this
possible?


Nov 16 '05 #3
Try:

public string[] AZ
{
get { return az; }
set { az = value; }
}

The serializer won't bother storing anything that can't roundtrip.
Once it sees that it can put AZ back where it found it, it will include
it in your XML.

Jason
http://www.expatsoftware.com/
Expat Software Consulting Services

Nov 16 '05 #4

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

Similar topics

10
by: Zap | last post by:
Widespread opinion is that public data members are evil, because if you have to change the way the data is stored in your class you have to break the code accessing it, etc. After reading this...
0
by: big A | last post by:
I am receiving an error stating that File or Assembly name <filname.dll>, or one of its dependencies, was not found In one assembly I have three abstract classes In another I have three...
3
by: Amy L. | last post by:
I have a class that contains a string array. However, I can't get this object to serialize in the xml output. Is there a trick to get a string to serialize? Thanks Amy.
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
12
by: tobias.sturn | last post by:
Hi! My prof told me always to make my members private or protected cause its standard to write setter and getter methodes.. Is that in your opinion correct? Cause I dont see any adventages to...
4
by: dani k | last post by:
How do I write my own serialization of a class that has non-serializable data members? this problem arose when I tried to serialize RSAParameters, for which the private stuff is not serializable
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
2
by: ilitirit | last post by:
Can anyone explain why the following program doesn't work? The attributes and elements of the MessageList class are not being generated. Am I doing something incorrectly? Or if this is a bug...
11
by: Yarco | last post by:
For example: <?php class Test { private $name = 'yarco'; } $p = new ReflectionPropery('Test', 'name'); print $p->getValue();
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
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
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...
0
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,...

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.