コード例 #1
0
        private static void LoadResource()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();

            using (Stream manifestResourceStream = executingAssembly.GetManifestResourceStream("TIM.T_KERNEL.Helper.PinyinDict.resources"))
            {
                using (ResourceReader resourceReader = new ResourceReader(manifestResourceStream))
                {
                    string resourceType;
                    byte[] resourceData;
                    resourceReader.GetResourceData("PinyinDictionary", out resourceType, out resourceData);
                    using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(resourceData)))
                    {
                        ChinesePinyin.pinyinDictionary = PinyinDictionary.Deserialize(binaryReader);
                    }
                }
            }
            using (Stream manifestResourceStream2 = executingAssembly.GetManifestResourceStream("TIM.T_KERNEL.Helper.CharDict.resources"))
            {
                using (ResourceReader resourceReader2 = new ResourceReader(manifestResourceStream2))
                {
                    string resourceType;
                    byte[] resourceData;
                    resourceReader2.GetResourceData("CharDictionary", out resourceType, out resourceData);
                    using (BinaryReader binaryReader2 = new BinaryReader(new MemoryStream(resourceData)))
                    {
                        ChinesePinyin.charDictionary = CharDictionary.Deserialize(binaryReader2);
                    }
                }
            }
            using (Stream manifestResourceStream3 = executingAssembly.GetManifestResourceStream("TIM.T_KERNEL.Helper.ChinesePY.txt"))
            {
                using (TextReader textReader = new StreamReader(manifestResourceStream3, Encoding.UTF8))
                {
                    ChinesePinyin.pinyinCustom = new Dictionary <char, string>();
                    while (true)
                    {
                        string str  = textReader.ReadLine();
                        bool   flag = str != null;
                        if (!flag)
                        {
                            break;
                        }
                        string[] strArray = str.Trim().Split(new char[]
                        {
                            ' '
                        });
                        bool flag2 = strArray.Length > 1 && strArray[0].Length == 1 && !ChinesePinyin.pinyinCustom.ContainsKey(strArray[0][0]);
                        if (flag2)
                        {
                            string str2  = strArray[1].ToUpper();
                            bool   flag3 = str2[str2.Length - 1] >= '1' && str2[str2.Length - 1] <= '5';
                            if (flag3)
                            {
                                str2 = str2.Substring(0, str2.Length - 1);
                            }
                            ChinesePinyin.pinyinCustom.Add(strArray[0][0], str2);
                        }
                    }
                }
            }
        }