Пример #1
0
        /// <summary>
        /// 使用 OPQ码 字符串初始化 <see cref="OPQCode"/> 类的新实例
        /// </summary>
        /// <param name="str">OPQ码字符串 或 包含OPQ码的字符串</param>
        private OPQCode(string str)
        {
            this._originalString = str;

            #region --解析 OPQCode--

            Match match = _regices.Value[0].Match(str);
            if (!match.Success)
            {
                throw new FormatException("无法解析所传入的字符串, 字符串非OPQ码格式!");
            }

            #endregion --解析 OPQCode--

            #region --解析OPQ码类型--

            if (!System.Enum.TryParse <OPQFunction>(match.Groups[1].Value, true, out _type))
            {
                this._type = OPQFunction.Unknown;    // 解析不出来的时候, 直接给一个默认
            }

            #endregion --解析OPQ码类型--

            #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, OPQDeCode(item.Groups[2].Value));
            }

            #endregion --解析键值对--
        }
Пример #2
0
        /// <summary>
        /// 初始化 <see cref="OPQCode"/> 类的新实例
        /// </summary>
        /// <param name="type">OPQ码类型</param>
        /// <param name="keyValues">包含的键值对</param>
        public OPQCode(OPQFunction 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;
        }