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);
        }
示例#2
0
        protected internal override T[] Deserialize(IntermediateReader input, ContentSerializerAttribute format, T[] existingInstance)
        {
            List <T> list = new List <T>();

            this.listHelper.Deserialize(input, format, list);
            return(list.ToArray());
        }
示例#3
0
        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);
        }
        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);
        }
示例#5
0
        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));
            }
        }
示例#6
0
 protected internal override TimeSpan Deserialize(IntermediateReader input, ContentSerializerAttribute format, TimeSpan existingInstance)
 {
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     return(XmlConvert.ToTimeSpan(input.Xml.ReadContentAsString()));
 }
示例#7
0
 protected internal override DateTime Deserialize(IntermediateReader input, ContentSerializerAttribute format, DateTime existingInstance)
 {
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     return(XmlConvert.ToDateTime(input.Xml.ReadContentAsString(), XmlDateTimeSerializationMode.RoundtripKind));
 }
示例#8
0
 protected internal override Type Deserialize(IntermediateReader input, ContentSerializerAttribute format, Type existingInstance)
 {
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     return(input.ReadTypeName());
 }
        /// <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);
        }
示例#10
0
        protected internal override List <T> Deserialize(IntermediateReader input, ContentSerializerAttribute format, List <T> existingInstance)
        {
            List <T> list = existingInstance;

            if (list == null)
            {
                list = new List <T>();
            }
            this.collectionHelper.Deserialize(input, format, list);
            return(list);
        }
示例#11
0
 protected internal override BoundingFrustum Deserialize(IntermediateReader input, ContentSerializerAttribute format, BoundingFrustum existingInstance)
 {
     if (input == null)
     {
         throw new ArgumentNullException("input");
     }
     if (format == null)
     {
         throw new ArgumentNullException("format");
     }
     return(new BoundingFrustum(input.ReadObject <Matrix>(BoundingFrustumSerializer.matrixFormat)));
 }
示例#12
0
        public XmlListReader(IntermediateReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            this.reader = reader;
            string text = reader.Xml.ReadContentAsString();
            IEnumerable <string> enumerable = text.Split(XmlListReader.listSeparators, StringSplitOptions.RemoveEmptyEntries);

            this.enumerator = enumerable.GetEnumerator();
            this.atEnd      = !this.enumerator.MoveNext();
        }
示例#13
0
        /// <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 override object Deserialize(IntermediateReader input, ContentSerializerAttribute format, object existingInstance)
        {
            T existingInstance2;

            if (existingInstance == null)
            {
                existingInstance2 = default(T);
            }
            else
            {
                existingInstance2 = ContentTypeSerializer <T> .CastType(existingInstance);
            }
            return(this.Deserialize(input, format, existingInstance2));
        }
        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);
        }
        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");
            }
            format = this.ApplyCustomFormatting(format);
            object obj = existingInstance;

            if (obj == null)
            {
                if (this.instanceConstructor == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.NoDefaultConstructor, new object[]
                    {
                        base.TargetType
                    }));
                }
                obj = this.instanceConstructor();
            }
            if (this.baseSerializer != null)
            {
                object obj2 = this.baseSerializer.Deserialize(input, format, obj);
                if (obj2 != obj)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.DeserializerConstructedNewInstance, new object[]
                    {
                        this.baseSerializer.GetType(),
                        this.baseSerializer.TargetType
                    }));
                }
            }
            foreach (ReflectiveSerializerMemberHelper current in this.memberHelpers)
            {
                current.Deserialize(input, obj);
            }
            if (this.collectionHelper != null)
            {
                this.collectionHelper.Deserialize(input, format, obj);
            }
            return(obj);
        }
        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);
        }
 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);
 }
示例#19
0
        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);
        }
示例#20
0
 /// <summary>Deserializes a strongly typed 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>
 protected internal abstract T Deserialize(IntermediateReader input, ContentSerializerAttribute format, T existingInstance);
 protected internal override T?Deserialize(IntermediateReader input, ContentSerializerAttribute format, T?existingInstance)
 {
     return(new T?(input.ReadRawObject <T>(this.underlyingFormat, this.underlyingTypeSerializer)));
 }