Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.
I have my main measure (_measurePercent) and public getter/setter (MeasurePercent) for this.

C#
private double _measurePercent;
public double MeasurePercent
{
    get
    {
        if (double.IsNaN(_measurePercent) || double.IsInfinity(_measurePercent))
           throw new Exception("...");
        return _measurePercent;
    }
    set
    {
        if(value > 100.0f || value < 0.0f)
           throw new Exception("...");
        _measurePercent = value;
    }
 }


I want to serialize in XML this value.
I know that XML Serialization doesn't work for private fields, so [XmlIgnore] on getter/setter won't help.
Serialization of getter/setter also doesn't work, because it uses _measurePercent which value isn't deserialized.
I want to ask, if it is posible to make this to work without writing my own XML Serializer.
Posted

1 solution

This should serialize just fine, since serialization works with public properties. Realize, of course, that since your properties can throw exceptions, those same exceptions may be thrown while the object is being serialized.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900