protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { if (input == null) { throw new ArgumentNullException("input"); } if (format == null) { throw new ArgumentNullException("format"); } IList list; if (existingInstance == null) { list = (IList)Activator.CreateInstance(base.TargetType); } else { list = this.CastType(existingInstance); } ContentSerializerAttribute contentSerializerAttribute = new ContentSerializerAttribute(); contentSerializerAttribute.ElementName = format.CollectionItemName; while (input.MoveToElement(format.CollectionItemName)) { list.Add(input.ReadObject <object>(contentSerializerAttribute)); } return(list); }
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { if (input == null) { throw new ArgumentNullException("input"); } if (format == null) { throw new ArgumentNullException("format"); } IDictionary dictionary; if (existingInstance == null) { dictionary = (IDictionary)Activator.CreateInstance(base.TargetType); } else { dictionary = this.CastType(existingInstance); } while (input.MoveToElement(format.CollectionItemName)) { input.Xml.ReadStartElement(); object key = input.ReadObject <object>(this.keyFormat); object value = input.ReadObject <object>(this.valueFormat); dictionary.Add(key, value); input.Xml.ReadEndElement(); } return(dictionary); }
protected internal override Dictionary <Key, Value> Deserialize(IntermediateReader input, ContentSerializerAttribute format, Dictionary <Key, Value> existingInstance) { if (input == null) { throw new ArgumentNullException("input"); } if (format == null) { throw new ArgumentNullException("format"); } Dictionary <Key, Value> dictionary = existingInstance; if (dictionary == null) { dictionary = new Dictionary <Key, Value>(); } while (input.MoveToElement(format.CollectionItemName)) { input.Xml.ReadStartElement(); Key key = input.ReadObject <Key>(this.keyFormat, this.keySerializer); Value value = input.ReadObject <Value>(this.valueFormat, this.valueSerializer); dictionary.Add(key, value); input.Xml.ReadEndElement(); } return(dictionary); }
public void Deserialize(IntermediateReader input, ContentSerializerAttribute format, object collection) { if (input == null) { throw new ArgumentNullException("input"); } if (format == null) { throw new ArgumentNullException("format"); } this.ValidateCollectionType(collection); IXmlListItemSerializer xmlListItemSerializer = this.contentSerializer as IXmlListItemSerializer; if (xmlListItemSerializer != null) { XmlListReader xmlListReader = new XmlListReader(input); while (!xmlListReader.AtEnd) { this.addToCollection(collection, xmlListItemSerializer.Deserialize(xmlListReader)); } return; } ContentSerializerAttribute contentSerializerAttribute = new ContentSerializerAttribute(); contentSerializerAttribute.ElementName = format.CollectionItemName; while (input.MoveToElement(format.CollectionItemName)) { this.addToCollection(collection, input.ReadObject <object>(contentSerializerAttribute, this.contentSerializer)); } }
/// <summary>Deserializes an intermediate XML file into a managed object.</summary> /// <param name="input">Intermediate XML file.</param> /// <param name="referenceRelocationPath">Final name of the output file used to relative encode external reference filenames.</param> public static T Deserialize <T>(XmlReader input, string referenceRelocationPath) { if (input == null) { throw new ArgumentNullException("input"); } Uri baseUri = IntermediateSerializer.RelocationPathToUri(referenceRelocationPath); IntermediateReader intermediateReader = new IntermediateReader(IntermediateSerializer.SingletonInstance, input, baseUri); T result; try { if (!intermediateReader.MoveToElement("XnaContent")) { throw intermediateReader.CreateInvalidContentException(Resources.NotIntermediateXml, new object[0]); } input.ReadStartElement(); T t = intermediateReader.ReadObject <T>(new ContentSerializerAttribute { ElementName = "Asset" }); intermediateReader.ReadSharedResources(); intermediateReader.ReadExternalReferences(); input.ReadEndElement(); result = t; } catch (XmlException ex) { throw intermediateReader.CreateInvalidContentException(ex, Resources.XmDeserializelException, new object[] { ex.Message }); } catch (FormatException ex2) { throw intermediateReader.CreateInvalidContentException(ex2, Resources.XmDeserializelException, new object[] { ex2.Message }); } catch (OverflowException ex3) { throw intermediateReader.CreateInvalidContentException(ex3, Resources.XmDeserializelException, new object[] { ex3.Message }); } catch (ArgumentException ex4) { throw intermediateReader.CreateInvalidContentException(ex4, Resources.XmDeserializelException, new object[] { ex4.Message }); } return(result); }
public void Deserialize(IntermediateReader input, object parentInstance) { if (!this.formatAttribute.FlattenContent) { if (this.formatAttribute.Optional) { if (!input.MoveToElement(this.formatAttribute.ElementName)) { return; } } else { input.Xml.MoveToContent(); } } if (this.formatAttribute.SharedResource) { this.DeserializeSharedResource(input, parentInstance); return; } this.DeserializeRegularObject(input, parentInstance); }