protected internal override void Serialize(IntermediateWriter output, Dictionary <TKey, TValue> value, ContentSerializerAttribute format) { foreach (var kvp in value) { output.Xml.WriteStartElement(format.CollectionItemName); output.WriteObject(kvp.Key, _keyFormat, _keySerializer); output.WriteObject(kvp.Value, _valueFormat, _valueSerializer); output.Xml.WriteEndElement(); } }
public void Serialize(IntermediateWriter output, object collection, ContentSerializerAttribute format) { var itemFormat = new ContentSerializerAttribute { ElementName = format.CollectionItemName }; foreach (var item in (IEnumerable)collection) output.WriteObject(item, itemFormat, _contentSerializer); }
protected internal override void Serialize( IntermediateWriter output, object value, ContentSerializerAttribute format) { // Create the item serializer attribute. var itemFormat = new ContentSerializerAttribute { ElementName = format.CollectionItemName }; // Read all the items. foreach (var item in (IList)value) { output.WriteObject(item, itemFormat); } }
protected internal override void Serialize(IntermediateWriter output, List <T> value, ContentSerializerAttribute format) { if (_itemSerializer is ElementSerializer <T> elementSerializer) { elementSerializer.Serialize(output, value); } else { // Create the item serializer attribute. var itemFormat = new ContentSerializerAttribute { ElementName = format.CollectionItemName }; // Read all the items. foreach (var item in value) { output.WriteObject(item, itemFormat, _itemSerializer); } } }
public static void Serialize <T>(XmlWriter output, T value, string referenceRelocationPath) { var serializer = new IntermediateSerializer(); var writer = new IntermediateWriter(serializer, output, referenceRelocationPath); output.WriteStartElement("XnaContent"); serializer._namespaceAliasHelper.WriteNamespaces(output, value); // Write the asset. var format = new ContentSerializerAttribute { ElementName = "Asset" }; writer.WriteObject <object>(value, format); // Process the shared resources and external references. writer.WriteSharedResources(); writer.WriteExternalReferences(); // Close the XnaContent element. output.WriteEndElement(); }