Serializing private members with public Propery getter doesn't wor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
XMLSerializer

Sahil Malik said:
Are you using XMLSerializer or BinaryFormatter?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik


punkbot said:
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?
 
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
 
Back
Top