0

Possible Duplicate:
Deserializing empty xml attribute value into nullable int property using XmlSerializer

I want to deserialize following XML into C# object. It contains elements with value of integer type or empty value: CustomerID=”1005” or CustomerID=””. Any ideas about how to get element value into property with nullable int.

<ExportDefinition>
  <DestinationDir>C:\Test\</DestinationDir>
  <CustomerID>1005</CustomerID>
</ExportDefinition>
public ExportDefinition GetExportDefinition(FileInfo exportDefFile)
        {
            if (!exportDefFile.Exists)
                throw new Exception(string.Format("Export definition file '{0}' does not exists.", exportDefFile.FullName));

            FileStream readFileStream = null;
            XmlSerializer serializerObj = null;
            ExportDefinition loadedObj = null;

            try
            {
                readFileStream = new FileStream(exportDefFile.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);

                serializerObj = new XmlSerializer(typeof(ExportDefinition));

                loadedObj = (ExportDefinition)serializerObj.Deserialize(readFileStream);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (readFileStream != null)
                    readFileStream.Close();
            }
            return loadedObj;
        }
Community
  • 1
  • 1
mrd
  • 2,095
  • 6
  • 23
  • 48

0 Answers0