Esempio n. 1
0
        public static void SerializeToBinaryFile(string filename, PhraseBopomofoDictionary dictionary)
        {
            var startTime = DateTime.Now;

            Log.Logger.Information($"開始將字典序列化至 bin 檔案:{filename}");

            using (var file = File.Create(filename))
            {
                Serializer.Serialize(file, dictionary);
                file.Flush();
            }

            Log.Logger.Information($"成功將字典序列化至 bin 檔案: {filename}。片語數量:{dictionary.Count}。費時:{DateTime.Now - startTime}");
        }
Esempio n. 2
0
        public static void SerializeToJsonFile(string filename, PhraseBopomofoDictionary dictionary)
        {
            var startTime = DateTime.Now;

            Log.Logger.Information($"開始將字典序列化至 json 檔案:{filename}");

            using (var writer = new StreamWriter(filename, false, Encoding.UTF8))
            {
                var serializer = JsonSerializer.Create();
                serializer.Serialize(writer, dictionary, typeof(PhraseBopomofoDictionary));
                writer.Flush();
            }

            Log.Logger.Information($"成功將字典序列化至 json 檔案: {filename}。片語數量:{dictionary.Count}。費時:{DateTime.Now - startTime}");
        }