Пример #1
0
        /// <summary>
        /// 获取一卦的彖辞。
        /// Get the text in Tuanzhuan of a hexagram.
        /// </summary>
        /// <param name="hexagram">
        /// 卦。
        /// The hexagram.
        /// </param>
        /// <returns>
        /// 彖辞。
        /// The text in Tuanzhuan.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="hexagram"/> 为 <c>null</c> 。
        /// <paramref name="hexagram"/> is <c>null</c>.
        /// </exception>
        public string this[ZhouyiHexagram hexagram]
        {
            get
            {
                if (hexagram is null)
                {
                    throw new ArgumentNullException(nameof(hexagram));
                }

                return(this.translation.TuanTexts[hexagram.Index - 1]);
            }
        }
Пример #2
0
        public string ApplyPattern(ZhouyiHexagram hexagram)
        {
            IEnumerable <string> BuildPlaceholders()
            {
                yield return(Environment.NewLine);

                yield return(this.numbers.Ordinal[hexagram.Index - 1]);

                yield return(hexagram.Name);

                yield return(hexagram.Text);

                yield return(hexagram.LowerTrigram.Name);

                yield return(hexagram.LowerTrigram.Nature);

                yield return(hexagram.UpperTrigram.Name);

                yield return(hexagram.UpperTrigram.Nature);

                yield return(this.ApplyPattern(hexagram.FirstLine));

                yield return(this.ApplyPattern(hexagram.SecondLine));

                yield return(this.ApplyPattern(hexagram.ThirdLine));

                yield return(this.ApplyPattern(hexagram.FourthLine));

                yield return(this.ApplyPattern(hexagram.FifthLine));

                yield return(this.ApplyPattern(hexagram.SixthLine));

                if (hexagram.ApplyNinesOrApplySixes is not null)
                {
                    yield return(this.ApplyPattern(hexagram.ApplyNinesOrApplySixes));
                }
                else
                {
                    yield return(string.Empty);
                }
            }

            return(string.Format(
                       hexagram.UpperTrigram.Equals(hexagram.LowerTrigram) ?
                       this.patterns.PureHexagramsToString :
                       this.patterns.HexagramsToString, BuildPlaceholders().ToArray()));
        }