Пример #1
0
        /// <summary>
        /// Constructor for recreating object during de-serialization
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        private DateTime(SerializationInfo info, StreamingContext context)
        {
            m_universal  = info.GetDateTime("m_universal");
            m_nanosecond = info.GetInt32("m_nanosecond");

            bool isCurrentTimeZone = info.GetBoolean("isCurrentTimeZone");

            if (isCurrentTimeZone)
            {
                m_timeZone = System.TimeZone.CurrentTimeZone;
            }
            else
            {
                m_timeZone = (System.TimeZone)info.GetValue("m_timeZone", typeof(System.TimeZone));
            }
            Debug.Assert(m_timeZone != null, "m_timeZone != null");

            m_base = m_timeZone.ToLocalTime(m_universal);
        }
Пример #2
0
        // This constructor is for cloning. The nanosecond parameter is the total of microseconds and
        // nanoseconds (ie. 0 to 1000000).
        private DateTime(System.DateTime baseValue, int nanosecond, System.TimeZone timeZone,
                         bool isUniversalTime)
        {
            Debug.Assert(nanosecond >= 0 && nanosecond < 1000000, "The nanosecond value is invalid -"
                         + " an exception should be thrown immediately after this.");

            if (isUniversalTime)
            {
                m_universal = baseValue;
                m_base      = timeZone.ToLocalTime(baseValue);
            }
            else
            {
                m_base      = baseValue;
                m_universal = timeZone.ToUniversalTime(baseValue);
            }

            m_nanosecond = nanosecond;
            m_timeZone   = timeZone;
        }