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)); } }
protected override BoneWeight[] Deserialize(IntermediateReader input, Microsoft.Xna.Framework.Content.ContentSerializerAttribute format, BoneWeight[] existingInstance) { string[] s = input.Xml.ReadContentAsString().Trim().Split(' '); if (s.Length > 0 && s.Length % 8 != 0) { throw new Exception("Too few data items for the BoneWeight"); } BoneWeight[] boneWeights = new BoneWeight[(int)(s.Length / 8)]; int index = 0; for (int i = 0; i < s.Length; i += 8, index++) { BoneWeight bw = new BoneWeight(); bw.weights.x = Single.Parse(s[i]); bw.weights.y = Single.Parse(s[i + 1]); bw.weights.z = Single.Parse(s[i + 2]); bw.weights.w = Single.Parse(s[i + 3]); bw.boneIndex0 = Int32.Parse(s[i + 4]); bw.boneIndex1 = Int32.Parse(s[i + 5]); bw.boneIndex2 = Int32.Parse(s[i + 6]); bw.boneIndex3 = Int32.Parse(s[i + 7]); boneWeights[index] = bw; } return(boneWeights); }
protected override LayerMask Deserialize(IntermediateReader input, ContentSerializerAttribute format, LayerMask existingInstance) { return(new LayerMask() { value = input.Xml.ReadContentAsInt() }); }
/// <summary> /// Deserializes the derived fields. /// </summary> /// <param name="input">The input.</param> /// <param name="format">The format.</param> /// <param name="existingInstance">The existing instance.</param> protected override void DeserializeDerivedFields(IntermediateReader input, ContentSerializerAttribute format, BoxEmitter existingInstance) { existingInstance.Width = input.ReadObject <Single>("Width"); existingInstance.Height = input.ReadObject <Single>("Height"); existingInstance.Depth = input.ReadObject <Single>("Depth"); existingInstance.Rotation = input.ReadObject <Vector3>("Rotation"); }
protected override Vector4[] Deserialize(IntermediateReader input, ContentSerializerAttribute format, Vector4[] existingInstance) { string str = input.Xml.ReadContentAsString().Trim(); if (string.IsNullOrWhiteSpace(str)) { return(new Vector4[0]); } string[] s = str.Split(' '); if ((s.Length % 4) != 0) { throw new Exception(String.Format("Not enough floats in the string for Vector4[] in element {0}. Was {1}.", format.ElementName, s.Length)); } Vector4[] vs = new Vector4[s.Length / 4]; for (int i = 0; i < vs.Length; i++) { try { int triIndex = i * 4; vs[i][0] = float.Parse(s[triIndex]); vs[i][1] = float.Parse(s[triIndex + 1]); vs[i][2] = float.Parse(s[triIndex + 2]); } catch (IndexOutOfRangeException) { throw new IndexOutOfRangeException("Error reading Vector4[] from string in element " + format.ElementName + ". i was " + i + " for a limit of " + vs.Length + " using " + s.Length + " numbers"); } } return(vs); }
/// <summary> /// Deserializes a $safeitemname$ object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized $safeitemname$ instance.</returns> protected override $safeitemname$ Deserialize(IntermediateReader input, ContentSerializerAttribute format, $safeitemname$ existingInstance) { $safeitemname$ value = existingInstance ?? default($safeitemname$); // TODO deserialize $safeitemname$ fields & properties... return value; }
/// <summary> /// Deserializes a DampingModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized DampingModifier instance.</returns> protected override DampingModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, DampingModifier existingInstance) { DampingModifier value = existingInstance ?? new DampingModifier(); value.DampingCoefficient = input.ReadObject <Single>("DampingCoefficient"); return(value); }
/// <summary> /// Deserializes a RotationModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized RotationModifier instance.</returns> protected override RotationModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, RotationModifier existingInstance) { RotationModifier value = existingInstance ?? new RotationModifier(); value.RotationRate = input.ReadObject <Vector3>("RotationRate"); return(value); }
protected override Emitter Deserialize(IntermediateReader input, ContentSerializerAttribute format, Emitter existingInstance) { Emitter value = existingInstance ?? new Emitter(); base.Deserialize(input, format, value); return(value); }
/// <summary> /// Deserializes a OpacityFastFadeModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized OpacityFastFadeModifier instance.</returns> protected override OpacityFastFadeModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, OpacityFastFadeModifier existingInstance) { OpacityFastFadeModifier value = existingInstance ?? new OpacityFastFadeModifier(); value.InitialOpacity = input.ReadObject <Single>("InitialOpacity"); return(value); }
/// <summary> /// Deserializes a VelocityClampModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized VelocityClampModifier instance.</returns> protected override VelocityClampModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, VelocityClampModifier existingInstance) { VelocityClampModifier value = existingInstance ?? new VelocityClampModifier(); value.MaximumVelocity = input.ReadObject <Single>("MaximumVelocity"); return(value); }
/// <summary> /// Deserializes a TriggerRandomOffsetController object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized TriggerRandomOffsetController instance.</returns> protected override TriggerRandomOffsetController Deserialize(IntermediateReader input, ContentSerializerAttribute format, TriggerRandomOffsetController existingInstance) { TriggerRandomOffsetController value = existingInstance ?? new TriggerRandomOffsetController(); value.Size = input.ReadObject <Vector3>("Size"); return(value); }
/// <summary> /// Deserializes a $safeitemname$ object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized $safeitemname$ instance.</returns> protected override $safeitemname$ Deserialize(IntermediateReader input, ContentSerializerAttribute format, $safeitemname$ existingInstance) { $safeitemname$ value = existingInstance ?? default($safeitemname$); // TODO deserialize $safeitemname$ fields & properties... return(value); }
/// <summary> /// Deserializes a CooldownController object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized CooldownController instance.</returns> protected override CooldownController Deserialize(IntermediateReader input, ContentSerializerAttribute format, CooldownController existingInstance) { CooldownController value = existingInstance ?? new CooldownController(); value.CooldownPeriod = input.ReadObject <Single>("CooldownPeriod"); return(value); }
/// <summary> /// Deserializes a HueShiftModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized HueShiftModifier instance.</returns> protected override HueShiftModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, HueShiftModifier existingInstance) { HueShiftModifier value = existingInstance ?? new HueShiftModifier(); value.HueShift = input.ReadObject <Single>("HueShift"); return(value); }
/// <summary> /// Deserializes a ScaleInterpolator2 object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized ScaleInterpolator2 instance.</returns> protected override ScaleInterpolator2 Deserialize(IntermediateReader input, ContentSerializerAttribute format, ScaleInterpolator2 existingInstance) { ScaleInterpolator2 value = existingInstance ?? new ScaleInterpolator2(); value.InitialScale = input.ReadObject <Single>("InitialScale"); value.FinalScale = input.ReadObject <Single>("FinalScale"); return(value); }
/// <summary> /// Deserializes a LinearGravityModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized LinearGravityModifier instance.</returns> protected override LinearGravityModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, LinearGravityModifier existingInstance) { LinearGravityModifier value = existingInstance ?? new LinearGravityModifier(); value.GravityVector = input.ReadObject <Vector3>("GravityVector"); value.Strength = input.ReadObject <Single> ("Strength"); return(value); }
/// <summary> /// Deserializes a ColourInterpolator2 object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized ColourInterpolator2 instance.</returns> protected override ColourInterpolator2 Deserialize(IntermediateReader input, ContentSerializerAttribute format, ColourInterpolator2 existingInstance) { ColourInterpolator2 value = existingInstance ?? new ColourInterpolator2(); value.InitialColour = input.ReadObject <Vector3>("InitialColour"); value.FinalColour = input.ReadObject <Vector3>("FinalColour"); return(value); }
protected override SharedResourceDictionary <TKey, TValue> Deserialize(IntermediateReader input, ContentSerializerAttribute format, SharedResourceDictionary <TKey, TValue> existingInstance) { if (existingInstance == null) { existingInstance = new SharedResourceDictionary <TKey, TValue>(); } while (input.MoveToElement(Keyformat.ElementName)) { if (default(TKey) is ValueType) { TKey key = input.ReadObject <TKey>(Keyformat); mKeys.Add(key); } else { input.ReadSharedResource(Keyformat, delegate(TKey item) { mKeys.Add(item); if (mKeys.Count == mNumberOfItem && mValues.Count == mNumberOfItem) { for (int i = 0; i < mNumberOfItem; i++) { existingInstance.Add(mKeys[i], mValues[i]); } } }); } if (default(TValue) is ValueType) { TValue value = input.ReadObject <TValue>(Valueformat); mValues.Add(value); } else { input.ReadSharedResource(Valueformat, delegate(TValue item) { mValues.Add(item); if (mKeys.Count == mNumberOfItem && mValues.Count == mNumberOfItem) { for (int i = 0; i < mNumberOfItem; i++) { existingInstance.Add(mKeys[i], mValues[i]); } } }); } mNumberOfItem++; } return(existingInstance); }
/// <summary> /// Deserializes a ColourRange object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized ColourRange instance.</returns> protected override ColourRange Deserialize(IntermediateReader input, ContentSerializerAttribute format, ColourRange existingInstance) { ColourRange value = default(ColourRange); value.Red = input.ReadObject <Range>("Red"); value.Green = input.ReadObject <Range>("Green"); value.Blue = input.ReadObject <Range>("Blue"); return(value); }
protected override Color Deserialize(IntermediateReader input, Microsoft.Xna.Framework.Content.ContentSerializerAttribute format, Color existingInstance) { string s = input.Xml.ReadContentAsString(); if (s.Length != 8 && s.Length != 6) { throw new Exception("Color string must either be AARRGGBB or RRGGBB. Was: " + s); } return(Color.Parse(s)); }
protected override Color[] Deserialize(IntermediateReader input, ContentSerializerAttribute format, Color[] existingInstance) { string[] s = input.Xml.ReadContentAsString().Trim().Split(' '); Color[] vs = new Color[s.Length]; for (int i = 0; i < s.Length; i++) { vs[i] = Color.Parse(s[i]); } return(vs); }
/// <summary> /// Deserializes a RotationRange object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized RotationRange instance.</returns> protected override RotationRange Deserialize(IntermediateReader input, ContentSerializerAttribute format, RotationRange existingInstance) { RotationRange value = default(RotationRange); value.Pitch = input.ReadObject <Range>("Pitch"); value.Yaw = input.ReadObject <Range>("Yaw"); value.Roll = input.ReadObject <Range>("Roll"); return(value); }
/// <summary> /// Deserializes a Range object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized Range instance.</returns> protected override Range Deserialize(IntermediateReader input, ContentSerializerAttribute format, Range existingInstance) { Range value = default(Range); CultureInfo invariantCulture = CultureInfo.InvariantCulture; value = Range.Parse(input.Xml.ReadString(), invariantCulture); return(value); }
protected override AudioClip Deserialize(IntermediateReader input, Microsoft.Xna.Framework.Content.ContentSerializerAttribute format, AudioClip existingInstance) { string s = input.Xml.ReadContentAsString(); AudioClip c = new AudioClip() { clip = s }; return(c); }
// Methods public XmlListReader(IntermediateReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } this.reader = reader; IEnumerable<string> enumerable = reader.Xml.ReadContentAsString().Split(listSeparators, StringSplitOptions.RemoveEmptyEntries); this.enumerator = enumerable.GetEnumerator(); this.atEnd = !this.enumerator.MoveNext(); }
/// <summary> /// Deserializes a SphereForceModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized SphereForceModifier instance.</returns> protected override SphereForceModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, SphereForceModifier existingInstance) { SphereForceModifier value = existingInstance ?? new SphereForceModifier(); value.Position = input.ReadObject <Vector3>("Position"); value.Radius = input.ReadObject <Single> ("Radius"); value.ForceVector = input.ReadObject <Vector3>("ForceVector"); value.Strength = input.ReadObject <Single> ("Strength"); return(value); }
protected override Guid Deserialize(IntermediateReader input, Microsoft.Xna.Framework.Content.ContentSerializerAttribute format, Guid existingInstance) { string s = input.Xml.ReadContentAsString(); Guid g; if (Guid.TryParse(s, out g)) { return(g); } return(Guid.Empty); }
/// <summary> /// Deserializes a OpacityInterpolator3 object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized OpacityInterpolator3 instance.</returns> protected override OpacityInterpolator3 Deserialize(IntermediateReader input, ContentSerializerAttribute format, OpacityInterpolator3 existingInstance) { OpacityInterpolator3 value = existingInstance ?? new OpacityInterpolator3(); value.InitialOpacity = input.ReadObject <Single>("InitialOpacity"); value.Median = input.ReadObject <Single>("Median"); value.MedianOpacity = input.ReadObject <Single>("MedianOpacity"); value.FinalOpacity = input.ReadObject <Single>("FinalOpacity"); return(value); }
/// <summary> /// Deserializes a ParticleEffect object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized ParticleEffect instance.</returns> protected override ParticleEffect Deserialize(IntermediateReader input, ContentSerializerAttribute format, ParticleEffect existingInstance) { ParticleEffect value = existingInstance ?? new ParticleEffect(); value.Name = input.ReadObject <String> ("Name"); value.Author = input.ReadObject <String> ("Author"); value.Description = input.ReadObject <String> ("Description"); value.Emitters = input.ReadObject <EmitterCollection>("Emitters", "Item"); return(value); }
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { var str = input.Xml.ReadString(); try { return Enum.Parse(TargetType, str, true); } catch (Exception ex) { throw input.NewInvalidContentException(ex, "Invalid enum value '{0}' for type '{1}'", str, TargetType.Name); } }
// Methods public XmlListReader(IntermediateReader reader) { if (reader == null) { throw new ArgumentNullException("reader"); } this.reader = reader; IEnumerable <string> enumerable = reader.Xml.ReadContentAsString().Split(listSeparators, StringSplitOptions.RemoveEmptyEntries); this.enumerator = enumerable.GetEnumerator(); this.atEnd = !this.enumerator.MoveNext(); }
internal static Exception CreateInvalidContentException(this IntermediateReader reader, string message, params object[] messageArgs) { ContentIdentity contentIdentity = new ContentIdentity(); contentIdentity.SourceFilename = reader.Xml.BaseURI; IXmlLineInfo xml = reader.Xml as IXmlLineInfo; if (xml != null) { contentIdentity.FragmentIdentifier = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { xml.LineNumber, xml.LinePosition }); } return(new InvalidContentException(string.Format(CultureInfo.CurrentCulture, message, messageArgs), contentIdentity)); }
/// <summary> /// Deserializes a BoxForceModifier object from intermediate XML format. /// </summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The strongly typed object containing the received data, or null if the /// deserializer should construct a new instance.</param> /// <returns>A deserialized BoxForceModifier instance.</returns> protected override BoxForceModifier Deserialize(IntermediateReader input, ContentSerializerAttribute format, BoxForceModifier existingInstance) { BoxForceModifier value = existingInstance ?? new BoxForceModifier(); value.Position = input.ReadObject <Vector3>("Position"); value.Width = input.ReadObject <Single> ("Width"); value.Height = input.ReadObject <Single> ("Height"); value.Depth = input.ReadObject <Single> ("Depth"); value.Force = input.ReadObject <Vector3>("Force"); value.Strength = input.ReadObject <Single> ("Strength"); return(value); }
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { var result = (IList) (existingInstance ?? Activator.CreateInstance(TargetType)); // Create the item serializer attribute. var itemFormat = new ContentSerializerAttribute(); itemFormat.ElementName = format.CollectionItemName; // Read all the items. while (input.MoveToElement(itemFormat.ElementName)) { var value = input.ReadObject<object>(itemFormat); result.Add(value); } return result; }
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; }
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { var result = existingInstance; if (result == null) { try { result = Activator.CreateInstance(TargetType, true); } catch (MissingMethodException e) { throw new Exception(string.Format("Couldn't create object of type {0}: {1}", TargetType.Name, e.Message), e); } } var reader = input.Xml; var depth = reader.Depth; // Read the next node. while (reader.Read()) { // Did we reach the end of this object? if (reader.NodeType == XmlNodeType.EndElement) break; Debug.Assert(reader.Depth == depth, "We are not at the right depth!"); if (reader.NodeType == XmlNodeType.Element) { var elementName = reader.Name; reader.ReadStartElement(); ElementInfo info; if (!_elements.TryGetValue(elementName, out info)) throw new InvalidContentException(string.Format("Element `{0}` was not found in type `{1}`.", elementName, TargetType)); var value = info.Serializer.Deserialize(input, format, null); info.Setter(result, value); reader.ReadEndElement(); continue; } // If we got here then we were not interested // in this node... so skip its children. reader.Skip(); } return result; }
protected internal override object Deserialize (IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { throw new System.NotImplementedException(); }
protected internal override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance) { var result = existingInstance; if (result == null) { try { result = Activator.CreateInstance(TargetType, true); } catch (MissingMethodException e) { throw new Exception(string.Format("Couldn't create object of type {0}: {1}", TargetType.Name, e.Message), e); } } // First deserialize the base type. if (_baseSerializer != null) _baseSerializer.Deserialize(input, format, result); // Now deserialize our own elements. foreach (var info in _elements) { if (!info.Attribute.FlattenContent) { if (!input.MoveToElement(info.Attribute.ElementName)) { // If the the element was optional then we can // safely skip it and continue. if (info.Attribute.Optional) continue; // We failed to find a required element. throw new InvalidContentException(string.Format("The Xml element `{0}` is required!", info.Attribute.ElementName)); } } if (info.Attribute.SharedResource) { Action<object> fixup = (o) => info.Setter(result, o); input.ReadSharedResource(info.Attribute, fixup); } else if (info.Setter == null) { var value = info.Getter(result); input.ReadObject(info.Attribute, info.Serializer, value); } else { var value = input.ReadObject<object>(info.Attribute, info.Serializer); info.Setter(result, value); } } return result; }
/// <summary>Deserializes an object from intermediate XML format.</summary> /// <param name="input">Location of the intermediate XML and various deserialization helpers.</param> /// <param name="format">Specifies the intermediate source XML format.</param> /// <param name="existingInstance">The object containing the received data, or null if the deserializer should construct a new instance.</param> protected internal abstract object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance);