public object Deserialize(XmlReader xmlReader, string encodingStyle) { Debug.Assert(null != _logicalType, "Reflection info not initialized before calling Serialize"); try { // Initialize the parser bool soap12; XmlSerializationReader serialReader = initXmlSerializationReader(xmlReader, encodingStyle, out soap12); xmlReader.MoveToContent(); // Get the correct deserializing type LogicalType deserializingType = resolveDeserializingType(xmlReader, serialReader, soap12); // Deserialize the element object deserializedObject; if (_isEncoded && (isNullableWithStructValue(deserializingType) || isComplexObjectValue(deserializingType))) { Type instType = deserializingType.IsNullableType ? deserializingType.NullableValueType.Type : deserializingType.Type; object fixupTarget = SerializationHelper.CreateInstance(instType); serialReader.DeserializeElement(deserializingType.Members, fixupTarget); serialReader.runFixups(); deserializedObject = fixupTarget; } else { ObjectFixup fixup = new ObjectFixup(deserializingType); serialReader.DeserializeElement(deserializingType.TypeAccessor, fixup); serialReader.runFixups(); deserializedObject = fixup.Object; } serialReader.CheckUnreferencedObjects(deserializedObject); return(deserializedObject); } catch (Exception e) { if (e is TargetInvocationException) { e = e.InnerException; } #if !FEATURE_LEGACYNETCF if (xmlReader is XmlTextReader) { XmlTextReader XmlTextReader = (XmlTextReader)xmlReader; throw new InvalidOperationException(SR.Format(SR.XmlSerializeErrorDetails, XmlTextReader.LineNumber.ToString(NumberFormatInfo.InvariantInfo), XmlTextReader.LinePosition.ToString(NumberFormatInfo.InvariantInfo)), e); } else #endif { throw new InvalidOperationException(SR.XmlSerializeError, e); } } }
/// <summary> /// Override this method to return the target's enumerable object member. /// </summary> protected override object GetTargetEnumerable(object target) { object enumerable = SerializationHelper.GetValue(target, m_member); if (enumerable == null && m_CanWrite) { SerializationHelper.SetValue(target, m_member, SerializationHelper.CreateInstance(((LogicalEnumerable)m_TargetType).Type)); enumerable = SerializationHelper.GetValue(target, m_member); } return(enumerable); }
/// <summary> /// Override this method to return the target's collection object member. /// </summary> protected override object GetTargetCollection(object target) { object collection = SerializationHelper.GetValue(target, m_member); if (collection == null && m_CanWrite) { SerializationHelper.SetValue(target, m_member, SerializationHelper.CreateInstance(((LogicalCollection)m_TargetType).Type)); collection = SerializationHelper.GetValue(target, m_member); } return(collection); }
/// <summary> /// Returns the target enumerable that will recieve the items stored in a de-serialized /// enumerable. By default, the target parameter is ignored and a new enumerable based /// on the m_TargetType member. Subclasses can override this method to specifiy a /// different enumerable. For example the MemberFixup class overrides this method to /// return the actual enumerable member of the fixup target. This allows enumerable /// items to be assigned directly into the member itself. /// </summary> protected virtual object GetTargetEnumerable(object target) { return(SerializationHelper.CreateInstance(((LogicalEnumerable)m_TargetType).Type)); }
/// <summary> /// Returns the target collection that will recieve the items stored in a de-serialized /// collection. By default, the target parameter is ignored and a new collection based /// on the m_TargetType member. Subclasses can override this method to specifiy a /// different collection. For example the MemberFixup class overrides this method to /// return the actual collection member of the fixup target. This allows collection /// items to be assigned directly into the member itself. /// </summary> protected virtual object GetTargetCollection(object target) { return(SerializationHelper.CreateInstance(((LogicalCollection)m_TargetType).Type)); }