Пример #1
0
        private Object ReadElementContent(Type deserializedType, XmlItemDefAttributeCollection itemDefAttributes = null)
        {
            if (XmlDeserializationProvider.IsNativelyDeserializable(deserializedType))
            {
                return(this.ReadNativeObject(deserializedType, false, itemDefAttributes));
            }

            return(this.Serializer.GetSubSerializer(deserializedType).SubDeserialize(
                       this.XmlReader, this.XmlReader.LocalName, false, itemDefAttributes
                       ));
        }
Пример #2
0
        /// <exception cref="XmlSerializationException">
        ///   An error occurred while deserializing the type.
        /// </exception>
        private Object Deserialize(XmlReader xmlReader, XmlDeserializationProvider xmlDeserializationProvider)
        {
            if (xmlReader == null)
            {
                throw new ArgumentNullException();
            }
            if (xmlDeserializationProvider == null)
            {
                throw new ArgumentNullException();
            }

            Object instance;

            if (!this.IsCustomSerialized)
            {
                try {
                    instance = Activator.CreateInstance(this.TargetType);
                } catch (Exception exception) {
                    var ex = new XmlSerializationException("The parameterless contructor of the type threw an exception. See inner exception for more details.", exception);
                    ex.Data.Add("Type Name", this.TargetType.FullName);
                    throw ex;
                }

                xmlDeserializationProvider.ReadAll(instance);
            }
            else
            {
                try {
                    instance = Activator.CreateInstance(this.TargetType, xmlDeserializationProvider);
                } catch (Exception exception) {
                    var ex = new XmlSerializationException("An error occurred while deserializing the type by its custom deserialization constructor. See inner exception for more details.", exception);
                    ex.Data.Add("Type Name", this.TargetType.FullName);
                    throw ex;
                }
            }

            if (xmlReader.NodeType == XmlNodeType.EndElement)
            {
                xmlReader.ReadEndElement();
            }

            return(instance);
        }