示例#1
0
        static public List <TranslationElementDTO> LoadTranslationsXML(string fileName, string filePath = @"C:\Temp\")
        {
            string fileWithPath = fileName;

            if (!fileWithPath.Contains(@":") && !fileWithPath.Contains(@"\"))
            {
                if (filePath.EndsWith(@"\"))
                {
                    fileWithPath = filePath + fileWithPath;
                }
                else
                {
                    fileWithPath = filePath + @"\" + fileWithPath;
                }
            }

            TranslationsDTO list = new TranslationsDTO();

            // Create an instance of System.Xml.Serialization.XmlSerializer
            XmlSerializer serializer = new XmlSerializer(list.GetType());

            // Create an instance of System.IO.TextReader
            // to load the serialized data from disk
            using (TextReader textReader = new StreamReader(fileWithPath))
            {
                // Assign the deserialized object to the new employeeList object
                list = (TranslationsDTO)serializer.Deserialize(textReader);
            }

            return(list.Translations);
        }
        static public List <TranslationElementDTO> LoadTranslationsXML(string fileName)
        {
            TranslationsDTO list = new TranslationsDTO();

            // Create an instance of System.Xml.Serialization.XmlSerializer
            XmlSerializer serializer = new XmlSerializer(list.GetType());

            // Create an instance of System.IO.TextReader
            // to load the serialized data from disk
            using (TextReader textReader = new StreamReader($@"C:\Temp\{fileName}"))
            {
                // Assign the deserialized object to the new employeeList object
                list = (TranslationsDTO)serializer.Deserialize(textReader);
            }

            return(list.Translations);
        }
示例#3
0
        static public void SaveAsXML(List <TranslationElementDTO> data, string fileName, string filePath = @"C:\Temp\")
        {
            TranslationsDTO list = new TranslationsDTO()
            {
                Translations = data
            };

            // Create an instance of System.Xml.Serialization.XmlSerializer
            XmlSerializer serializer = new XmlSerializer(list.GetType());

            // Create an instance of System.IO.TextWriter
            // to save the serialized object to disk
            using (TextWriter textWriter = new StreamWriter($@"{filePath}{fileName}"))
            {
                // Serialize the employeeList object
                serializer.Serialize(textWriter, list);
            }
        }
示例#4
0
        static public List <TranslationElementDTO> LoadTranslationsXML(string fileName)
        {
            string fileWithPath = FilePathCheck(fileName);

            SRInfoHelper.Log("Loading " + fileWithPath);
            TranslationsDTO list = new TranslationsDTO();

            // Create an instance of System.Xml.Serialization.XmlSerializer
            XmlSerializer serializer = new XmlSerializer(list.GetType());

            // Create an instance of System.IO.TextReader
            // to load the serialized data from disk
            if (File.Exists(fileWithPath))
            {
                using (TextReader textReader = new StreamReader(fileWithPath))
                {
                    // Assign the deserialized object to the new employeeList object
                    list = (TranslationsDTO)serializer.Deserialize(textReader);
                }
            }

            return(list.Translations);
        }