public void Serialize(IntermediateWriter output, object parentInstance)
        {
            object obj = this.valueGetter(parentInstance);

            if (obj == null && !this.formatAttribute.AllowNull)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, Resources.NullElementNotAllowed, new object[]
                {
                    this.formatAttribute.ElementName
                }));
            }
            if (this.formatAttribute.Optional)
            {
                if (obj == null)
                {
                    return;
                }
                if (this.valueSetter == null && this.typeSerializer.ObjectIsEmpty(obj))
                {
                    return;
                }
            }
            if (this.formatAttribute.SharedResource)
            {
                output.WriteSharedResource <object>(obj, this.formatAttribute);
                return;
            }
            output.WriteObject <object>(obj, this.formatAttribute, this.typeSerializer);
        }
Exemple #2
0
 protected internal override void Serialize(IntermediateWriter output, BoundingFrustum value, ContentSerializerAttribute format)
 {
     if (output == null)
     {
         throw new ArgumentNullException("output");
     }
     output.WriteObject <Matrix>(value.Matrix, BoundingFrustumSerializer.matrixFormat);
 }
 protected internal override void Serialize(IntermediateWriter output, object value, ContentSerializerAttribute format)
 {
     if (output == null)
     {
         throw new ArgumentNullException("output");
     }
     if (format == null)
     {
         throw new ArgumentNullException("format");
     }
     foreach (DictionaryEntry dictionaryEntry in this.CastType(value))
     {
         output.Xml.WriteStartElement(format.CollectionItemName);
         output.WriteObject <object>(dictionaryEntry.Key, this.keyFormat);
         output.WriteObject <object>(dictionaryEntry.Value, this.valueFormat);
         output.Xml.WriteEndElement();
     }
 }
Exemple #4
0
        public void Serialize(IntermediateWriter output, ContentSerializerAttribute format, object collection)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            this.ValidateCollectionType(collection);
            IEnumerable enumerable = (IEnumerable)collection;

            if (this.contentSerializer is IXmlListItemSerializer)
            {
                ContentSerializerAttribute contentSerializerAttribute = new ContentSerializerAttribute();
                contentSerializerAttribute.FlattenContent = true;
                bool        flag       = true;
                IEnumerator enumerator = enumerable.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object current = enumerator.Current;
                        if (flag)
                        {
                            flag = false;
                        }
                        else
                        {
                            output.Xml.WriteWhitespace(" ");
                        }
                        output.WriteRawObject <object>(current, contentSerializerAttribute, this.contentSerializer);
                    }
                    return;
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            ContentSerializerAttribute contentSerializerAttribute2 = new ContentSerializerAttribute();

            contentSerializerAttribute2.ElementName = format.CollectionItemName;
            foreach (object current2 in enumerable)
            {
                output.WriteObject <object>(current2, contentSerializerAttribute2, this.contentSerializer);
            }
        }
Exemple #5
0
 protected internal override void Serialize(IntermediateWriter output, Dictionary <Key, Value> value, ContentSerializerAttribute format)
 {
     if (output == null)
     {
         throw new ArgumentNullException("output");
     }
     if (format == null)
     {
         throw new ArgumentNullException("format");
     }
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     foreach (KeyValuePair <Key, Value> current in value)
     {
         output.Xml.WriteStartElement(format.CollectionItemName);
         output.WriteObject <Key>(current.Key, this.keyFormat, this.keySerializer);
         output.WriteObject <Value>(current.Value, this.valueFormat, this.valueSerializer);
         output.Xml.WriteEndElement();
     }
 }
        protected internal override void Serialize(IntermediateWriter output, object value, ContentSerializerAttribute format)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (format == null)
            {
                throw new ArgumentNullException("format");
            }
            ContentSerializerAttribute contentSerializerAttribute = new ContentSerializerAttribute();

            contentSerializerAttribute.ElementName = format.CollectionItemName;
            foreach (object current in this.CastType(value))
            {
                output.WriteObject <object>(current, contentSerializerAttribute);
            }
        }
        /// <summary>Serializes an object into an intermediate XML file.</summary>
        /// <param name="output">The output XML stream.</param>
        /// <param name="value">The object to be serialized.</param>
        /// <param name="referenceRelocationPath">Final name of the output file, used to relative encode external reference filenames.</param>
        public static void Serialize <T>(XmlWriter output, T value, string referenceRelocationPath)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            Uri baseUri = IntermediateSerializer.RelocationPathToUri(referenceRelocationPath);
            IntermediateWriter intermediateWriter = new IntermediateWriter(IntermediateSerializer.SingletonInstance, output, baseUri);

            output.WriteStartElement("XnaContent");
            new XmlNamespaces(intermediateWriter).WriteNamespaces(value);
            ContentSerializerAttribute contentSerializerAttribute = new ContentSerializerAttribute();

            contentSerializerAttribute.ElementName = "Asset";
            intermediateWriter.WriteObject <object>(value, contentSerializerAttribute);
            intermediateWriter.WriteSharedResources();
            intermediateWriter.WriteExternalReferences();
            output.WriteEndElement();
        }