private CqMsg(string message) { OriginalString = message; Contents = new List <CqCode> (); // 搜索消息中的 CQ码 MatchCollection matches = _regex[0].Matches(message); if (matches.Count > 0) { foreach (Match match in matches) { CqCode tempCode = new CqCode(); #region --解析 CQ码 类型-- CqCodeType type = CqCodeType.Unknown; if (System.Enum.TryParse <CqCodeType> (match.Groups[1].Value, true, out type)) { tempCode.Type = type; } #endregion #region --键值对解析-- tempCode.Dictionary = new Dictionary <string, string> (); MatchCollection kvResult = _regex[1].Matches(match.Groups[2].Value); foreach (Match kvMatch in kvResult) { tempCode.Dictionary.Add(kvMatch.Groups[1].Value, kvMatch.Groups[2].Value); } #endregion Contents.Add(tempCode); } } }
private void Parse() { MatchCollection matches = _regex[0].Matches(this.OriginalString); if (matches.Count > 0) { foreach (Match match in matches) { CqCode tempCode = new CqCode(); #region --初始化CqCode-- tempCode.OriginalString = match.Groups[0].Value; tempCode.Index = match.Index; #endregion #region --解析CQ码类型-- CqCodeType type = CqCodeType.Unknown; if (System.Enum.TryParse <CqCodeType> (match.Groups[1].Value, true, out type)) { tempCode.Type = type; } #endregion #region --键值对解析-- if (tempCode.Dictionary == null) { tempCode.Dictionary = new Dictionary <string, string> (); } MatchCollection kvResult = _regex[1].Matches(match.Groups[2].Value); foreach (Match kvMatch in kvResult) { tempCode.Dictionary.Add(kvMatch.Groups[1].Value, kvMatch.Groups[2].Value); } #endregion Contents.Add(tempCode); } } }