Feedback

C# - Serializable TimeSpan

Veröffentlicht von am 4/8/2008
(1 Bewertungen)
Da TimeSpan nicht so einfach serialisierbar zu sein scheint, hab ich da mal was gebastelt.

inspiriert von http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic18670.aspx
 [Serializable]
    public class SerializableTimeSpan
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SerializableTimeSpan"/> class.
        /// </summary>
        public SerializableTimeSpan() { }

        /// <summary>
        /// Initializes a new instance of the <see cref="SerializableTimeSpan"/> class.
        /// </summary>
        /// <param name="dauer">The original timeSpan.</param>
        public SerializableTimeSpan(TimeSpan dauer)
        {
            this.Duration = dauer;
        }

        private TimeSpan duration;

        /// <summary>
        /// Gets or sets the duration.
        /// </summary>
        /// <value>The duration.</value>
        /// <remarks>Das echte Property</remarks>
        [XmlIgnore]
        public TimeSpan Duration
        {
            get { return duration; }
            set { duration = value; }
        }

        /// <summary>
        /// Gets or sets the duration of the XML.
        /// </summary>
        /// <value>The duration of the XML.</value>
        /// <remarks>Property für XML</remarks>
        [XmlElement("Duration")]
        public string XmlDuration
        {
            get { return Duration.ToString(); }
            set { Duration = TimeSpan.Parse(value); }
        }
    }

Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!