all groups > dotnet xml > september 2005 >
You're in the

dotnet xml

group:

xml serialize properties



xml serialize properties ocampoj NO[at]SPAM gmail.com
9/5/2005 1:46:10 PM
dotnet xml: I am having a problem serializing an object. I have a very simple
class.

[Serializable]
public class Phone : SwcDomainObject
{
private string areaCode;
private string prefix;
private string suffix;
private string extension;

public string AreaCode
{
get { return areaCode; }
set { areaCode = value; }
}

public string Prefix
{
get { return prefix; }
set { prefix = value; }
}

public string Suffix
{
get { return suffix; }
set { suffix = value; }
}

public string Extension
{
get { return extension; }
set { extension = value; }
}

public string FullPhone
{
get{return this.areaCode + " " + this.prefix + " " + this.suffix;}
}

}
OUTPUT:
<PhoneWork>
<AreaCode>252</AreaCode>
<Prefix>332</Prefix>
<Suffix>4117</Suffix>
</PhoneWork>

Everything serializes fine except for the FullPhone Accessor. When
that serializes it doesn't hold the value in the xml document. I can
only assume since you are using the xml serialization as more of a
state holder. That function accesors are not serialized only static
primitive datatypes? Is there anyway I can force the serialization to
occur on this accessor?

TIA

JoSkillz
Re: xml serialize properties ocampoj NO[at]SPAM gmail.com
9/5/2005 8:01:03 PM
Never mind I figured it out. In order for any of the object properties
to be serialized in XML they must expose both a setter and getter.
AddThis Social Bookmark Button