コード例 #1
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(IICalendar).IsAssignableFrom(objectType))
                {
                    s = new iCalendarSerializer();
                }
                else if (typeof(ICalendarComponent).IsAssignableFrom(objectType))
                {
                    if (typeof(IEvent).IsAssignableFrom(objectType))
                    {
                        s = new EventSerializer();
                    }
                    else if (typeof(IUniqueComponent).IsAssignableFrom(objectType))
                    {
                        s = new UniqueComponentSerializer();
                    }
                    else
                    {
                        s = new ComponentSerializer();
                    }
                }
                else if (typeof(ICalendarProperty).IsAssignableFrom(objectType))
                {
                    s = new PropertySerializer();
                }
                else if (typeof(ICalendarParameter).IsAssignableFrom(objectType))
                {
                    s = new ParameterSerializer();
                }
                else if (typeof(string).IsAssignableFrom(objectType))
                {
                    s = new StringSerializer();
                }
                else if (objectType.GetTypeInfo().IsEnum)
                {
                    s = new EnumSerializer(objectType);
                }
                else if (typeof(TimeSpan).IsAssignableFrom(objectType))
                {
                    s = new TimeSpanSerializer();
                }
                else if (typeof(int).IsAssignableFrom(objectType))
                {
                    s = new IntegerSerializer();
                }
                else if (typeof(Uri).IsAssignableFrom(objectType))
                {
                    s = new UriSerializer();
                }
                else if (typeof(ICalendarDataType).IsAssignableFrom(objectType))
                {
                    s = m_DataTypeSerializerFactory.Build(objectType, ctx);
                }
                // 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);
        }
コード例 #2
0
 // save the intermediate ics file for the source type represented in ical
 private BlobStorageResponse SerializeIcalEventsToIcs(iCalendar ical, SourceType type)
 {
     var serializer = new DDay.iCal.Serialization.iCalendar.iCalendarSerializer();
     var ics_text = serializer.SerializeToString(ical);
     var ics_bytes = Encoding.UTF8.GetBytes(ics_text);
     var containername = this.id;
     return bs.PutBlob(containername, containername + "_" + type.ToString() + ".ics", new Hashtable(), ics_bytes, "text/calendar");
 }