예제 #1
0
파일: Dict.cs 프로젝트: menozz/mirelle
        /// <summary>
        /// Add two dicts
        /// </summary>
        /// <param name="dict">Other dict</param>
        /// <returns></returns>
        public Dict Add(Dict dict)
        {
            var result = new Dict();

              foreach (var curr in Data)
            result.Set(curr.Key, curr.Value);

              foreach (var curr in dict.Data)
            result.Set(curr.Key, curr.Value);

              return result;
        }
예제 #2
0
파일: Printer.cs 프로젝트: menozz/mirelle
        /// <summary>
        /// Print a dict
        /// </summary>
        /// <param name="dict">Dict to print</param>
        private static void PrintDict(Dict dict)
        {
            var keys = dict.Keys();
              var maxLength = keys.Max(str => str.Length);

              Console.WriteLine("{");

              foreach(var curr in keys)
            Console.WriteLine("  {0,-" +  maxLength.ToString() + "} => {1}", curr, dict.Get(curr));

              Console.WriteLine("}");
        }
예제 #3
0
파일: File.cs 프로젝트: menozz/mirelle
        /// <summary>
        /// Save the dict to file
        /// </summary>
        /// <param name="dict">Dict</param>
        public void SaveDict(Dict dict)
        {
            Create();

              var keys = dict.Keys();
              for(int idx = 0; idx < keys.Length; idx++)
              {
            var str = (idx == 0 ? "" : "\r\n") + keys[idx] + "\r\n" + dict.Get(keys[idx]);
            var buf = System.Text.Encoding.UTF8.GetBytes(str);
            FileStream.Write(buf, 0, buf.Length);
              }

              Close();
        }
예제 #4
0
파일: File.cs 프로젝트: menozz/mirelle
        /// <summary>
        /// Load a dict from file
        /// </summary>
        /// <returns></returns>
        public Dict LoadDict()
        {
            if (FileStream == null) Open();
              FileStream.Seek(0, SeekOrigin.Begin);
              var array = ReadAll().Split(new[] { "\r\n" }, StringSplitOptions.None);

              var dict = new Dict();
              for (int idx = 0; idx < array.Length / 2; idx++)
            dict.Set(array[idx * 2], array[idx * 2 + 1]);

              return dict;
        }