This should work:
[XmlIgnore]
public int? Age { get; set; }
[XmlElement("Age")]
public string AgeAsText
{
get { return (Age.HasValue) ? Age.ToString() : null; }
set { Age = !string.IsNullOrEmpty(value) ? int.Parse(value) : default(int?); }
}
More Related Contents:
- “Type not expected”, using DataContractSerializer – but it’s just a simple class, no funny stuff?
- Can I serialize Anonymous Types as xml?
- Using .Net what limitations (if any) are there in using the XmlSerializer?
- Can Json.NET serialize / deserialize to / from a stream?
- Using Json.NET converters to deserialize properties
- What is the correct way to make a custom .NET Exception serializable?
- Can I use a Regex in an XPath expression?
- Does XSLT have a Split() function?
- Best way to get InnerXml of an XElement?
- Simplest way to have a configuration file in a Windows Forms C# application
- XmlSerializer: remove unnecessary xsi and xsd namespaces
- Best way to encode text data for XML
- Serialize a nullable int
- How to localize when JSON-serializing?
- What is the correct format to use for Date/Time in an XML file
- How to deserialize a JObject to .NET object
- XmlSerializer – There was an error reflecting type
- Does .NET 4 have a built-in JSON serializer/deserializer?
- How to solve “unable to switch the encoding” error when inserting XML into SQL Server
- DataContractSerializer vs XmlSerializer: Pros and Cons of each serializer
- How to use XPath with XElement or LINQ?
- Does .Net 4.5 support XML 1.1 yet (for characters invalid in XML 1.0)?
- replace WCF built-in JavascriptSerializer with Newtonsoft Json.Net json serializer
- Any way to make DataContractJsonSerializer serialize Dictionaries properly?
- How do I specify XML serialization attributes to support namespace prefixes during deserialization in .NET?
- How do you use XMLSerialize for Enum typed properties in c#?
- JSON serialization of array with polymorphic objects
- Performance: XDocument versus XmlDocument
- What’s the best way to jSON serialize a .NET DataTable in WCF?
- Serializing a list of Key/Value pairs to XML