示例#1
0
        /// <summary>
        /// Initialise the m_tzi member.
        /// </summary>
        /// <param name="info">The Tzi data from the registry.</param>
        private void InitTzi(byte[] info)
        {
            if (info.Length != Marshal.SizeOf(m_TZI))
            {
                throw new ArgumentException("Information size is incorrect", "info");
            }

            // Could have sworn there's a Marshal operation to pack bytes into
            // a structure, but I can't see it. Do it manually.

            GCHandle h = GCHandle.Alloc(info, GCHandleType.Pinned);

            try
            {
                m_TZI = (TZI)Marshal.PtrToStructure(h.AddrOfPinnedObject(), typeof(TZI));
            }
            finally
            {
                h.Free();
            }
        }
示例#2
0
 private TimeZoneInfo(XmlNode tzNode)
 {
     m_TZI = new TZI();
     //<Tz dn="(GMT+04:30) Kabul" sn="Afghanistan Standard Time" dln="Afghanistan Daylight Time" bias="-270" sbias="0" dlbias="-60" ddate="0,0,0,0,0,0,0,0" sdate="0,0,0,0,0,0,0,0" idx="1" />
     foreach (XmlAttribute attrib in tzNode.Attributes)
     {
         if (attrib.Name.Equals("id"))
         {
             m_Id = attrib.Value;
         }
         if (attrib.Name.Equals("dn"))
         {
             m_DisplayName = attrib.Value;
         }
         else if (attrib.Name.Equals("sn"))
         {
             m_StandardName = attrib.Value;
         }
         else if (attrib.Name.Equals("dln"))
         {
             m_DaylightName = attrib.Value;
         }
         else if (attrib.Name.Equals("bias"))
         {
             m_TZI.bias = int.Parse(attrib.Value);
         }
         else if (attrib.Name.Equals("sbias"))
         {
             m_TZI.standardBias = int.Parse(attrib.Value);
         }
         else if (attrib.Name.Equals("dlbias"))
         {
             m_TZI.daylightBias = int.Parse(attrib.Value);
         }
         else if (attrib.Name.Equals("ddate"))
         {
             m_TZI.daylightDate = new SYSTEMTIME(attrib.Value);
         }
         else if (attrib.Name.Equals("sdate"))
         {
             m_TZI.standardDate = new SYSTEMTIME(attrib.Value);
         }
         else if (attrib.Name.Equals("idx"))
         {
             m_Index = int.Parse(attrib.Value);
         }
         else if (attrib.Name.Equals("sshort"))
         {
             m_ShortStandardName = attrib.Value;
         }
         else if (attrib.Name.Equals("dlshort"))
         {
             m_ShortDaylightName = attrib.Value;
         }
         if (string.IsNullOrEmpty(m_ShortDaylightName))
         {
             m_ShortDaylightName = m_DaylightName;
         }
         if (string.IsNullOrEmpty(m_ShortStandardName))
         {
             m_ShortStandardName = m_StandardName;
         }
     }
     //Log.Debug(this.ToString());
 }
        /// <summary>
        /// Initialise the m_tzi member.
        /// </summary>
        /// <param name="info">The Tzi data from the registry.</param>
        private void InitTzi(byte[] info)
        {
            if (info.Length != Marshal.SizeOf(m_tzi))
            {
                throw new ArgumentException("Information size is incorrect",
                                                                     "info");
            }

            // Could have sworn there's a Marshal operation to pack bytes into
            // a structure, but I can't see it. Do it manually.

            GCHandle h = GCHandle.Alloc(info, GCHandleType.Pinned);

            try
            {
                m_tzi = (TZI)Marshal.PtrToStructure(h.AddrOfPinnedObject(),
                                                              typeof(TZI));
            }
            finally
            {
                h.Free();
            }
        }