/// <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); }
/// <summary> /// Get a trigram from its name. /// </summary> /// <param name="卦名">The name.</param> /// <param name="result">The trigram.</param> /// <returns>A value indicates whether the trigram has been found or not.</returns> public static bool 获取经卦(char 卦名, [NotNullWhen(true)] out 经卦?result) { var all = Properties.Resources.经卦卦名对照; var index = all.IndexOf(卦名); if (index == -1) { result = null; return(false); } result = new 经卦(index, 卦名, 获取卦对应的自然现象(index), 获取卦画(index)); return(true); }
/// <summary> /// Get a hexagram from its two trigrams. /// </summary> /// <param name="主卦">The lower trigram.</param> /// <param name="客卦">The upper trigram.</param> /// <param name="result">The hexagram.</param> /// <returns>Always <c>true</c> .</returns> /// <exception cref="ArgumentNullException">At least one argument is null.</exception> public static bool 获取别卦(经卦 主卦, 经卦 客卦, [NotNullWhen(true)] out 别卦?result) { if (主卦 is null) { throw new ArgumentNullException(nameof(主卦)); } if (客卦 is null) { throw new ArgumentNullException(nameof(客卦)); } int index; using (var ms = new MemoryStream(Properties.Resources.别卦经卦对照)) { ms.Position = 客卦.Index * 8 + 主卦.Index; index = ms.ReadByte(); } result = 获取别卦(index, 主卦, 客卦); return(true); }
private static 别卦 获取别卦(int index, 经卦 主卦, 经卦 客卦) { string 卦名; using (var ms = new MemoryStream(Properties.Resources.别卦卦名对照)) { for (byte r = 0; r < index; r++) { for (; ;) { var br = ms.ReadByte(); if (br == 30) { break; } } } List <byte> bytes = new List <byte>(8); for (; ;) { var br = ms.ReadByte(); if (br == 30) { break; } bytes.Add((byte)br); } 卦名 = Encoding.UTF8.GetString(bytes.ToArray()); } string 卦辞; 爻[] 各爻 = new 爻[6]; var gindex = Properties.Resources.ResourceManager.GetObject($"G{index}") as byte[]; Debug.Assert(gindex is not null); using (var str = new MemoryStream(gindex)) { { List <byte> bytes = new List <byte>(100); for (; ;) { var br = str.ReadByte(); if (br == 31) { break; } bytes.Add((byte)br); } 卦辞 = Encoding.UTF8.GetString(bytes.ToArray()); } for (int i = 0; i < 6; i++) { List <byte> bytes = new List <byte>(100); for (; ;) { var br = str.ReadByte(); if (br == 30) { break; } bytes.Add((byte)br); } 阴阳 阴阳; if (i < 3) { 阴阳 = 主卦.卦画[i]; } else { 阴阳 = 客卦.卦画[i - 3]; } 各爻[i] = new 爻(i + 1, 阴阳, Encoding.UTF8.GetString(bytes.ToArray())); } } string?用辞 = index switch { 0 => Properties.Resources.乾卦用辞, 1 => Properties.Resources.坤卦用辞, _ => null }; return(new 别卦(index, 卦名, 卦辞, 用辞, 各爻)); }