Beispiel #1
0
        public ChineseChar(char ch)
        {
            if (!IsValidChar(ch))
            {
                throw new NotSupportedException(AssemblyResource.CHARACTER_NOT_SUPPORTED);
            }
            this.chineseCharacter = ch;
            CharUnit charUnit = charDictionary.GetCharUnit(ch);

            this.strokeNumber = charUnit.StrokeNumber;
            this.pinyinCount  = charUnit.PinyinCount;
            this.isPolyphone  = charUnit.PinyinCount > 1;
            for (int i = 0; i < this.pinyinCount; i++)
            {
                PinyinUnit pinYinUnitByIndex = pinyinDictionary.GetPinYinUnitByIndex(charUnit.PinyinIndexList[i]);
                this.pinyinList[i] = pinYinUnitByIndex.Pinyin;
            }
        }
Beispiel #2
0
        /// <summary>ChineseChar类的构造函数。</summary>
        /// <param name="ch">指定的汉字字符。</param>
        /// <exception cref="T:System.NotSupportedException">
        ///   字符不在简体中文扩展字符集中。
        /// </exception>
        /// <remarks>
        /// 请参阅<see cref="T:Microsoft.International.Converters.PinYinConverter.ChineseChar" />来查看使用ChineseChar的实例。
        /// </remarks>
        public ChineseChar(char ch)
        {
            if (!IsValidChar(ch))
            {
                throw new NotSupportedException(Properties.Resources.CHARACTER_NOT_SUPPORTED);
            }
            ChineseCharacter = ch;
            var charUnit = charDictionary.GetCharUnit(ch);

            StrokeNumber = charUnit.StrokeNumber;
            PinyinCount  = charUnit.PinyinCount;
            IsPolyphone  = charUnit.PinyinCount > 1;
            var pu = new List <PinyinUnit>();

            for (var index = 0; index < PinyinCount; ++index)
            {
                var pinYinUnitByIndex = pinyinDictionary.GetPinYinUnitByIndex(charUnit.PinyinIndexList[index]);
                pu.Add(pinYinUnitByIndex);
            }
            Pinyins = pu.Any() ? pu.Select(c => c.Pinyin).ToArray() : null;
        }