/// <summary>
        /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param>
        /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param>
        public void Serialize(Stream stream, VehicleFamily obj)
        {
            var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings());

            using (xmlWriter)
            {
                DCSerializer.WriteObject(xmlWriter, obj);
            }
        }
Example #2
0
        /// <summary>
        /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param>
        /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param>
        public void Serialize(Stream stream, ApplicationSettings obj)
        {
            var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings());

            using (xmlWriter)
            {
                DCSerializer.WriteObject(xmlWriter, obj);
            }
        }
Example #3
0
        /// <summary>
        /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param>
        /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param>
        public void Serialize(Stream stream, ScriptContainer obj)
        {
            var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings());

            using (xmlWriter)
            {
                DCSerializer.WriteObject(xmlWriter, obj);
            }
        }
Example #4
0
        /// <summary>
        /// Serializes an <see cref="T:System.Object" /> using the specified <see cref="T:System.IO.Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="T:System.IO.Stream" /> that the <see cref="T:System.Object" /> will be serialized to.</param>
        /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param>
        public void Serialize(Stream stream, LauncherCollection obj)
        {
            var xmlWriter = XmlWriter.Create(stream, RetrieveXMLWriterSettings());

            using (xmlWriter)
            {
                DCSerializer.WriteObject(xmlWriter, obj);
            }
        }
Example #5
0
        public static Message Serialize(object anySerializableObject)
        {
            DataContractSerializer DCSerializer = new DataContractSerializer(typeof(Home));

            if (anySerializableObject == typeof(Home))
            {
                DCSerializer = new DataContractSerializer(typeof(Home));
            }
            else if (anySerializableObject == typeof(string))
            {
                DCSerializer = new DataContractSerializer(typeof(string));
            }
            using (var memoryStream = new MemoryStream())
            {
                DCSerializer.WriteObject(memoryStream, anySerializableObject);
                return(new Message {
                    Data = memoryStream.ToArray()
                });
                //return new Message { MemStream = memoryStream };
            }
        }
        /// <summary>
        /// Serializes the <see cref="T:System.Object" /> to a file using the specified <see cref="T:System.IO.Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="T:System.IO.Stream" /> to the specified location and what <see cref="T:System.IO.FileMode" /> it's using.</param>
        /// <param name="obj">The <see cref="T:System.Object" /> being serialized.</param>
        /// <exception cref="ArgumentNullException">stream - The stream being used can't be null!</exception>
        /// <exception cref="ArgumentNullException">obj - The object being serialized can't be null!</exception>
        public override void Serialize(Stream stream, CelestialBody obj)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream), "The stream being used can't be null!");
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj), "The object being serialized can't be null!");
            }

            WriterSettings.Indent = true;
            WriterSettings.NewLineOnAttributes = true;

            Writer = XmlWriter.Create(stream, WriterSettings);

            using (Writer)
            {
                try
                {
                    DCSerializer.WriteObject(Writer, obj);
                }
                catch (InvalidDataContractException e)
                {
                    Console.WriteLine(e.Message);
                    throw;
                }
                catch (SerializationException e)
                {
                    Console.WriteLine(e.Message);
                    throw;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    throw;
                }
            }
        }