DDay.iCal.Serialization.iCalendar.UTCOffsetSerializer.Deserialize C# (CSharp) Метод

Deserialize() публичный Метод

public Deserialize ( TextReader tr ) : object
tr TextReader
Результат object
        public override object Deserialize(TextReader tr)
        {
            string value = tr.ReadToEnd();

            IUTCOffset offset = CreateAndAssociate() as IUTCOffset;
            if (offset != null)
            {
                // Decode the value as necessary
                value = Decode(offset, value);

                Match match = Regex.Match(value, @"(\+|-)(\d{2})(\d{2})(\d{2})?");
                if (match.Success)
                {
                    try
                    {
                        // NOTE: Fixes bug #1874174 - TimeZone positive UTCOffsets don't parse correctly
                        if (match.Groups[1].Value == "+")
                            offset.Positive = true;
                        offset.Hours = Int32.Parse(match.Groups[2].Value);
                        offset.Minutes = Int32.Parse(match.Groups[3].Value);
                        if (match.Groups[4].Success)
                            offset.Seconds = Int32.Parse(match.Groups[4].Value);
                    }
                    catch
                    {
                        return null;
                    }
                    return offset;
                }

                return false;
            }
            return null;
        }
    }

Usage Example

Пример #1
0
 public UTCOffset(string value)
     : this()
 {
     UTCOffsetSerializer serializer = new UTCOffsetSerializer();            
     CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
 }