Example #1
0
 public void Serialize(System.Xml.XmlTextWriter xtw)
 {
     foreach (object obj in m_Array)
     {
         IXCalSerializable serializer = SerializerFactory.Create(obj);
         if (serializer != null)
         {
             serializer.Serialize(xtw);
         }
     }
 }
Example #2
0
 public override string SerializeToString()
 {
     if (m_Binary.Uri != null)
     {
         IXCalSerializable serializer = SerializerFactory.Create(m_Binary.Uri);
         return serializer.SerializeToString();
     }
     else
     {
         UTF8Encoding encoding = new UTF8Encoding();
         return Encode(encoding.GetString(m_Binary.Data));
     }
 }        
        virtual public void Serialize(XmlTextWriter xtw)
        {
            if (Object.Name != null)
            {
                // Serialize "VERSION" before any other properties
                if (Object.Properties.ContainsKey("VERSION"))
                {
                    Property          p          = (Property)Object.Properties["VERSION"];
                    IXCalSerializable serializer = SerializerFactory.Create(p);
                    if (serializer != null)
                    {
                        serializer.Serialize(xtw);
                    }
                }

                foreach (DictionaryEntry de in Object.Properties)
                {
                    // Don't serialize "VERSION" again, we've already done it above.
                    if (de.Key.Equals("VERSION"))
                    {
                        continue;
                    }

                    Property          p          = (Property)de.Value;
                    IXCalSerializable serializer = SerializerFactory.Create(p);
                    if (serializer != null)
                    {
                        serializer.Serialize(xtw);
                    }
                }

                foreach (DictionaryEntry de in Object.Parameters)
                {
                    Parameter         p          = (Parameter)de.Value;
                    IXCalSerializable serializer = SerializerFactory.Create(p);
                    if (serializer != null)
                    {
                        serializer.Serialize(xtw);
                    }
                }
            }

            foreach (DDay.iCal.Components.iCalObject obj in Object.Children)
            {
                IXCalSerializable serializer = SerializerFactory.Create(obj);
                if (serializer != null)
                {
                    serializer.Serialize(xtw);
                }
            }
        }
Example #4
0
        public override string SerializeToString()
        {
            List <string> values = new List <string>();

            foreach (Period p in m_RDate.Periods)
            {
                IXCalSerializable serializer = SerializerFactory.Create(p);
                if (serializer != null)
                {
                    values.Add(serializer.SerializeToString());
                }
            }

            return(string.Join(",", values.ToArray()));
        }
        virtual public void Serialize(XmlTextWriter xtw)
        {
            Type type = m_dataType.GetType();
            IXCalSerializable serializer = null;

            Type serializerType = Type.GetType(GetType().Namespace + "." + type.Name + "Serializer", false, true);

            if (serializerType != null)
            {
                serializer = (IXCalSerializable)Activator.CreateInstance(serializerType, new object[] { m_dataType });
            }

            if (serializer == null)
            {
                serializer = new FieldSerializer(m_dataType);
            }

            if (serializer != null)
            {
                xtw.WriteStartElement(m_dataType.Name.ToLower());

                if (serializer is IParameterSerializable)
                {
                    IParameterSerializable paramSerializer = (IParameterSerializable)serializer;
                    List <Parameter>       Parameters      = paramSerializer.Parameters;
                    foreach (Parameter param in paramSerializer.Parameters)
                    {
                        xtw.WriteAttributeString(param.Name.ToLower(), string.Join(",", param.Values.ToArray()));
                    }
                }

                // Determine if we should serialize the data of this serializer
                // as CDATA instead of a standard string.
                if (serializer.GetType().GetCustomAttributes(typeof(CDataAttribute), true).Length > 0)
                {
                    xtw.WriteCData(serializer.SerializeToString());
                }
                else
                {
                    xtw.WriteString(serializer.SerializeToString());
                }

                xtw.WriteEndElement();
            }
        }
        public override void Serialize(System.Xml.XmlTextWriter xtw)
        {
            xtw.WriteStartElement(m_Component.Name.ToLower());

            // Get a list of fields and properties
            List <object> items = this.FieldsAndProperties;

            // Alphabetize the list of fields & properties we just obtained
            items.Sort(new FieldPropertyAlphabetizer());

            // Iterate through each item and attempt to serialize it
            foreach (object item in items)
            {
                FieldInfo    field     = null;
                PropertyInfo prop      = null;
                Type         itemType  = null;
                string       itemName  = null;
                object[]     itemAttrs = null;

                if (item is FieldInfo)
                {
                    field    = (FieldInfo)item;
                    itemType = field.FieldType;
                    itemName = field.Name;
                }
                else
                {
                    prop     = (PropertyInfo)item;
                    itemType = prop.PropertyType;
                    itemName = prop.Name;
                }

                // Get attributes that are attached to each item
                itemAttrs = (field != null) ? field.GetCustomAttributes(true) : prop.GetCustomAttributes(true);

                // Get the item's value
                object obj = (field == null) ? prop.GetValue(Component, null) : field.GetValue(Component);

                // Adjust the items' name to be iCal-compliant
                if (obj is iCalObject)
                {
                    iCalObject ico = (iCalObject)obj;
                    if (ico.Name == null)
                    {
                        ico.Name = itemName.ToUpper().Replace("_", "-");
                    }

                    // If the property is non-standard, then replace
                    // it with an X-name
                    if (!ico.Name.StartsWith("X-"))
                    {
                        foreach (object attr in itemAttrs)
                        {
                            if (attr is NonstandardAttribute)
                            {
                                ico.Name = "X-" + ico.Name;
                                break;
                            }
                        }
                    }
                }

                // Retrieve custom attributes for this field/property
                if (obj is iCalDataType)
                {
                    ((iCalDataType)obj).Attributes = itemAttrs;
                }

                // Get the default value of the object, if available
                object defaultValue = null;
                foreach (Attribute a in itemAttrs)
                {
                    if (a is DefaultValueAttribute)
                    {
                        defaultValue = ((DefaultValueAttribute)a).Value;
                    }
                }

                // Create a serializer for the object
                IXCalSerializable serializer = SerializerFactory.Create(obj);

                // To continue, the default value must either not be set,
                // or it must not match the actual value of the item.
                if (defaultValue == null ||
                    (serializer != null && !serializer.SerializeToString().Equals(defaultValue.ToString())))
                {
                    // FIXME: enum values cannot name themselves; we need to do it for them.
                    // For this to happen, we probably need to wrap enum values into a
                    // class that inherits from iCalObject.
                    if (itemType.IsEnum)
                    {
                        xtw.WriteStartElement(itemName.ToLower().Replace("_", "-"));
                    }

                    // Actually serialize the object
                    if (serializer != null)
                    {
                        serializer.Serialize(xtw);
                    }

                    if (itemType.IsEnum)
                    {
                        xtw.WriteEndElement();
                    }
                }
            }

            // If any extra serialization is necessary, do it now
            base.Serialize(xtw);

            // Close the component
            xtw.WriteEndElement();
        }