Beispiel #1
0
 /// <summary>
 /// Writes an enumeration of <see cref="DateTime"/> values to this stream. The <see cref="DateTime"/> values
 /// will be available in the specified binary format.
 /// </summary>
 /// <param name="values">The <see cref="DateTime"/> values to write.</param>
 /// <param name="format">The binary format in which the <see cref="DateTime"/> values will be written.</param>
 public void Write(IEnumerable <DateTime> values, BinaryDateTimeFormat format)
 {
     foreach (DateTime value in values)
     {
         Write(value, format);
     }
 }
 /// <summary>
 /// Reads the specified number of <see cref="DateTime"/> values from the current stream into a
 /// <see cref="DateTime"/> array. The <see cref="DateTime"/> values are available in the specified binary
 /// format.
 /// </summary>
 /// <param name="count">The number of <see cref="DateTime"/> values to read.</param>
 /// <param name="format">The binary format, in which the <see cref="DateTime"/> values will be read.</param>
 /// <returns>The <see cref="DateTime"/> array read from the current stream.</returns>
 public DateTime[] ReadDateTimes(int count, BinaryDateTimeFormat format)
 {
     DateTime[] values = new DateTime[count];
     for (int i = 0; i < values.Length; i++)
     {
         values[i] = ReadDateTime(format);
     }
     return(values);
 }
Beispiel #3
0
        /// <summary>
        /// Reads a <see cref="DateTime"/> from the current stream. The <see cref="DateTime"/> is available in the
        /// specified binary format.
        /// </summary>
        /// <param name="format">The binary format, in which the <see cref="DateTime"/> will be read.</param>
        /// <returns>The <see cref="DateTime"/> read from the current stream.</returns>
        public DateTime ReadDateTime(BinaryDateTimeFormat format)
        {
            switch (format)
            {
            case BinaryDateTimeFormat.CTime:
                return(new DateTime(1970, 1, 1).ToLocalTime().AddSeconds(ReadUInt32()));

            case BinaryDateTimeFormat.NetTicks:
                return(new DateTime(ReadInt64()));

            default:
                throw new ArgumentOutOfRangeException("format", "The specified binary datetime format is invalid");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Writes a <see cref="DateTime"/> to this stream. The <see cref="DateTime"/> will be available in the
        /// specified binary format.
        /// </summary>
        /// <param name="value">The value to write.</param>
        /// <param name="format">The binary format in which the <see cref="DateTime"/> will be written.</param>
        public void Write(DateTime value, BinaryDateTimeFormat format)
        {
            switch (format)
            {
            case BinaryDateTimeFormat.CTime:
                Write((uint)(new DateTime(1970, 1, 1) - value.ToLocalTime()).TotalSeconds);
                break;

            case BinaryDateTimeFormat.NetTicks:
                Write(value.Ticks);
                break;

            default:
                throw new ArgumentOutOfRangeException("format", "The specified binary datetime format is invalid.");
            }
        }