/// <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); }
protected internal override T Deserialize(IntermediateReader input, ContentSerializerAttribute format, T existingInstance) { if (input == null) { throw new ArgumentNullException("input"); } XmlListReader xmlListReader = new XmlListReader(input); T result = this.Deserialize(xmlListReader); if (!xmlListReader.AtEnd) { throw input.CreateInvalidContentException(Resources.TooManyEntriesInXmlList, new object[0]); } return(result); }
private void DeserializeRegularObject(IntermediateReader input, object parentInstance) { if (this.valueSetter != null) { object value = input.ReadObject <object>(this.formatAttribute, this.typeSerializer); this.valueSetter(parentInstance, value); return; } object obj = this.valueGetter(parentInstance); if (obj == null) { throw input.CreateInvalidContentException(Resources.CantSerializeReadOnlyNull, new object[] { this.formatAttribute.ElementName }); } input.ReadObject <object>(this.formatAttribute, this.typeSerializer, obj); }
private void DeserializeSharedResource(IntermediateReader input, object parentInstance) { if (this.valueSetter == null) { throw new InvalidOperationException(Resources.ReadOnlySharedResource); } Action <object> fixup = delegate(object value) { if (!this.typeSerializer.IsTargetType(value)) { throw input.CreateInvalidContentException(Resources.WrongSharedResourceType, new object[] { this.typeSerializer.TargetType, value.GetType() }); } this.valueSetter(parentInstance, value); }; input.ReadSharedResource <object>(this.formatAttribute, fixup); }
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { if (input == null) { throw new ArgumentNullException("input"); } string text = input.Xml.ReadContentAsString(); object result; try { result = Enum.Parse(base.TargetType, text); } catch (ArgumentException innerException) { throw input.CreateInvalidContentException(innerException, Resources.InvalidEnumValue, new object[] { text, base.TargetType }); } return(result); }