XmlSerializer: The string '' is not a valid AllXsd value

前端 未结 5 1578
独厮守ぢ
独厮守ぢ 2020-12-20 10:52

I\'m getting this message,\"The string \'7/22/2006 12:00:00 AM\' is not a valid AllXsd value.\", when deserializing an XML, the element contains a date, this is the property

5条回答
  •  太阳男子
    2020-12-20 11:35

    AllocationDate is a mandatory field but can be supplied as blank which is handled by representing it by AllocationDateString:

        private DateTime? _allocationDate;
    
        [XmlIgnore]
        public DateTime? AllocationDate
        {
            get { return _allocationDate; }
            set { _allocationDate = value; }
        }
    
        [XmlAttribute("AllocationDateTime")]
        public string AllocationDateTimeString
        {
            get
            {
                return _allocationDate.HasValue ? XmlConvert.ToString(_allocationDate.Value, XmlDateTimeSerializationMode.Unspecified)
                : string.Empty;
            }
            set
            {
                _allocationDate = !string.IsNullOrEmpty(value) ? XmlConvert.ToDateTime(value, XmlDateTimeSerializationMode.Unspecified) : (DateTime?)null;
            }
        }
    

提交回复
热议问题