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)); } }
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())); }
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(); }