Ejemplo n.º 1
0
        public virtual string ToXml()
        {
            var xmlSerializer = new XmlSerializer(typeof(Sitemap));

            using (var textWriter = new StringWriterUtf8())
            {
                xmlSerializer.Serialize(textWriter, this);
                return(textWriter.ToString());
            }
        }
Ejemplo n.º 2
0
        public IFileInfo SerializeAndSave(T objectToSerialize, DirectoryInfo targetDirectory, string targetFileName)
        {
            ValidateArgumentNotNull(objectToSerialize);

            var xmlSerializer = new XmlSerializer(typeof(T));

            using (var textWriter = new StringWriterUtf8())
            {
                xmlSerializer.Serialize(textWriter, objectToSerialize);
                var xmlString = textWriter.ToString();
                return(_fileSystemWrapper.WriteFile(xmlString, targetDirectory, targetFileName));
            }
        }
Ejemplo n.º 3
0
        public FileInfo SerializeAndSave(T objectToSerialize, DirectoryInfo targetDirectory, string targetFileName)
        {
            ValidateArgumentNotNull(objectToSerialize);

            var xmlSerializer    = new XmlSerializer(typeof(T));
            var customNamespaces = new XmlSerializerNamespaces();

            customNamespaces.Add(Namespaces.RootNamespacePrefix, Namespaces.RootNamespace);
            customNamespaces.Add(Namespaces.ImageNamespacePrefix, Namespaces.ImageNamespace);

            using (var textWriter = new StringWriterUtf8())
            {
                xmlSerializer.Serialize(textWriter, objectToSerialize, customNamespaces);
                var xmlString = textWriter.ToString();
                var path      = Path.Combine(targetDirectory.FullName, targetFileName);

                return(_fileSystemWrapper.WriteFile(xmlString, path));
            }
        }