コード例 #1
0
        /// <summary>
        /// Get a trigram from its painting.
        /// </summary>
        /// <param name="卦画">
        /// The painting.
        /// Its property <see cref="卦画.爻数"/> should be 3.
        /// </param>
        /// <param name="result">The trigram.</param>
        /// <returns>A value indicates whether the trigram has been found or not.</returns>
        /// <exception cref="ArgumentNullException"> <paramref name="卦画"/> is null.</exception>
        public static bool 获取经卦(卦画 卦画, [NotNullWhen(true)] out 经卦?result)
        {
            if (卦画 is null)
            {
                throw new ArgumentNullException(nameof(卦画));
            }
            if (卦画.爻数 != 3)
            {
                result = null;
                return(false);
            }
            int index = default;

            using (var ms = new MemoryStream(Properties.Resources.经卦卦画对照))
            {
                var b = 卦画.ToByte();
                for (int i = 0; i < 8; i++)
                {
                    if (ms.ReadByte() == b)
                    {
                        index = i;
                        break;
                    }
                }
            }
            result = new 经卦(index, 获取卦名(index), 获取卦对应的自然现象(index), 卦画);
            return(true);
        }
コード例 #2
0
ファイル: 经卦.cs プロジェクト: yueyinqiu/ZhouyiFramework
 internal 经卦(int index, char 卦名, char 自然现象, 卦画 卦画)
 {
     this.Index = index;
     this.卦名    = 卦名;
     this.自然属性  = 自然现象;
     阴阳[] 各爻阴阳 = 卦画.ToArray();
     this.初爻阴阳 = 各爻阴阳[0];
     this.中爻阴阳 = 各爻阴阳[1];
     this.爻阴阳  = 各爻阴阳[2];
 }
コード例 #3
0
        /// <summary>
        /// Convert from a <see cref="string"/> .
        /// </summary>
        /// <param name="s">
        /// The string represents the painting.
        /// </param>
        /// <param name="result">The painting.</param>
        /// <returns>A value indicates whether it has been successfully converted or not.</returns>
        /// <exception cref="ArgumentNullException"> <paramref name="s"/> is null.</exception>
        public static bool TryParse(string s, [NotNullWhen(true)] out 卦画?result)
        {
            if (s == null)
            {
                throw new ArgumentNullException(nameof(s));
            }
            List <阴阳> r = new List <阴阳>(6);

            foreach (var c in s)
            {
                if (c < '0' || c > '9')
                {
                    result = null;
                    return(false);
                }
                r.Add(c % 2 == 0 ? 阴阳.阴 : 阴阳.阳);
            }
            result = new 卦画(r.ToArray());
            return(true);
        }
コード例 #4
0
        /// <summary>
        /// Get a hexagram from its painting.
        /// </summary>
        /// <param name="卦画">
        /// The painting.
        /// Its property <see cref="卦画.爻数"/> should be 6.
        /// </param>
        /// <param name="result">The hexagram.</param>
        /// <returns>A value indicates whether the hexagram has been found or not.</returns>
        /// <exception cref="ArgumentException"> <see cref="卦画.爻数"/> of <paramref name="卦画"/> isn't 6.</exception>
        /// <exception cref="ArgumentNullException"> <paramref name="卦画"/> is null.</exception>
        public static bool 获取别卦(卦画 卦画, [NotNullWhen(true)] out 别卦?result)
        {
            if (卦画 is null)
            {
                throw new ArgumentNullException(nameof(卦画));
            }
            if (卦画.爻数 != 6)
            {
                result = null;
                return(false);
            }

            经卦.获取经卦(new 卦画(false, 卦画[0], 卦画[1], 卦画[2]), out 经卦? 主卦);
            Debug.Assert(主卦 is not null);

            经卦.获取经卦(new 卦画(false, 卦画[3], 卦画[4], 卦画[5]), out 经卦? 客卦);
            Debug.Assert(客卦 is not null);

            return(获取别卦(主卦, 客卦, out result));
        }