简体   繁体   中英

Custom Serialization/De-serialization Issue

Given this XML element:

<SampleA>0</SampleA>

Why is reader.HasValue resolving to false when the element clearly has a value ("0")?

if (reader.HasValue)
    this.SampleA = Int32.Parse(reader.ReadElementString("SampleA"));

Is this the correct property to check for the above purpose?

This could be because your reader is on another node.

You may want to try:

 if( reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "SampleA") {
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM