コード例 #1
0
        public override object Deserialize(TextReader tr)
        {
            string value = tr.ReadToEnd();

            // Create the day specifier and associate it with a calendar object
            IWeekDay ds = CreateAndAssociate() as IWeekDay;

            // Decode the value, if necessary
            value = Decode(ds, value);

            Match match = Regex.Match(value, @"(\+|-)?(\d{1,2})?(\w{2})");

            if (match.Success)
            {
                if (match.Groups[2].Success)
                {
                    ds.Offset = Convert.ToInt32(match.Groups[2].Value);
                    if (match.Groups[1].Success && match.Groups[1].Value.Contains("-"))
                    {
                        ds.Offset *= -1;
                    }
                }
                ds.DayOfWeek = RecurrencePatternSerializer.GetDayOfWeek(match.Groups[3].Value);
                return(ds);
            }

            return(null);
        }
コード例 #2
0
 public RecurrencePattern(string value) :
     this()
 {
     if (value != null)
     {
         DDay.iCal.Serialization.iCalendar.RecurrencePatternSerializer serializer = new DDay.iCal.Serialization.iCalendar.RecurrencePatternSerializer();
         CopyFrom(serializer.Deserialize(new StringReader(value)) as ICopyable);
     }
 }
コード例 #3
0
        /// <summary>
        /// Returns a serializer that can be used to serialize and object
        /// of type <paramref name="objectType"/>.
        /// <note>
        ///     TODO: Add support for caching.
        /// </note>
        /// </summary>
        /// <param name="objectType">The type of object to be serialized.</param>
        /// <param name="ctx">The serialization context.</param>
        virtual public ISerializer Build(Type objectType, ISerializationContext ctx)
        {
            if (objectType != null)
            {
                ISerializer s = null;

                if (typeof(IAttachment).IsAssignableFrom(objectType))
                {
                    s = new AttachmentSerializer();
                }
                else if (typeof(IAttendee).IsAssignableFrom(objectType))
                {
                    s = new AttendeeSerializer();
                }
                else if (typeof(IDateTime).IsAssignableFrom(objectType))
                {
                    s = new DateTimeSerializer();
                }
                else if (typeof(IFreeBusyEntry).IsAssignableFrom(objectType))
                {
                    s = new FreeBusyEntrySerializer();
                }
                else if (typeof(IGeographicLocation).IsAssignableFrom(objectType))
                {
                    s = new GeographicLocationSerializer();
                }
                else if (typeof(IOrganizer).IsAssignableFrom(objectType))
                {
                    s = new OrganizerSerializer();
                }
                else if (typeof(IPeriod).IsAssignableFrom(objectType))
                {
                    s = new PeriodSerializer();
                }
                else if (typeof(IPeriodList).IsAssignableFrom(objectType))
                {
                    s = new PeriodListSerializer();
                }
                else if (typeof(IRecurrencePattern).IsAssignableFrom(objectType))
                {
                    s = new RecurrencePatternSerializer();
                }
                else if (typeof(IRequestStatus).IsAssignableFrom(objectType))
                {
                    s = new RequestStatusSerializer();
                }
                else if (typeof(IStatusCode).IsAssignableFrom(objectType))
                {
                    s = new StatusCodeSerializer();
                }
                else if (typeof(ITrigger).IsAssignableFrom(objectType))
                {
                    s = new TriggerSerializer();
                }
                else if (typeof(IUTCOffset).IsAssignableFrom(objectType))
                {
                    s = new UTCOffsetSerializer();
                }
                else if (typeof(IWeekDay).IsAssignableFrom(objectType))
                {
                    s = new WeekDaySerializer();
                }
                // Default to a string serializer, which simply calls
                // ToString() on the value to serialize it.
                else
                {
                    s = new StringSerializer();
                }

                // Set the serialization context
                if (s != null)
                {
                    s.SerializationContext = ctx;
                }

                return(s);
            }
            return(null);
        }