/// <summary> /// 使用 CQ码 字符串初始化 <see cref="CQCode"/> 类的新实例 /// </summary> /// <param name="str">CQ码字符串 或 包含CQ码的字符串</param> private CQCode(string str) { this._originalString = str; #region --解析 CqCode-- Match match = _regices.Value[0].Match(str); if (!match.Success) { throw new FormatException("无法解析所传入的字符串, 字符串非CQ码格式!"); } #endregion #region --解析CQ码类型-- if (!System.Enum.TryParse <CQFunction> (match.Groups[1].Value, true, out _type)) { this._type = CQFunction.Unknown; // 解析不出来的时候, 直接给一个默认 } #endregion #region --解析键值对-- MatchCollection collection = _regices.Value[1].Matches(match.Groups[2].Value); this._items = new Dictionary <string, string> (collection.Count); foreach (Match item in collection) { this._items.Add(item.Groups[1].Value, CQApi.CQDeCode(item.Groups[2].Value)); } #endregion }
/// <summary> /// 初始化 <see cref="CQCode"/> 类的新实例 /// </summary> /// <param name="type">CQ码类型</param> /// <param name="keyValues">包含的键值对</param> public CQCode(CQFunction type, params KeyValuePair <string, string>[] keyValues) { this._type = type; this._items = new Dictionary <string, string> (keyValues.Length); foreach (KeyValuePair <string, string> item in keyValues) { this._items.Add(item.Key, item.Value); } this._originalString = null; }
/// <summary> /// 构造CQ码实例 /// </summary> /// <param name="cqFunction">CQ码类型</param> /// <param name="dataObj"></param> internal CQCode(CQFunction cqFunction, object dataObj) { this.Function = cqFunction; this.CQData = dataObj; }