Пример #1
0
        public override void Interpret(EnumDescContext context)
        {
            if (context == null || string.IsNullOrWhiteSpace(context.EnumHtml))
            {
                return;
            }

            //枚举成员的匹配正则式
            Regex regex = new Regex(@"<tr>[\r\n\s]*<td>(?<alias>((?!</td>).|\n)*)</td>[\r\n\s]*<td>(?<name>((?!</td>).|\n)*)</td>[\r\n\s]*<td>(?<desc>((?!</td>).|\n)*)</td>[\r\n\s]*</tr>", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);

            MatchCollection mc = regex.Matches(context.EnumHtml);

            List <EnumOption> optionList = new List <EnumOption>();

            //当前2的次幂数
            int index = 0;

            //遍历枚举成员处理
            foreach (Match m in mc)
            {
                EnumOption option = new EnumOption();

                option.Name        = m.Groups["name"].Value.Trim();
                option.Alias       = m.Groups["alias"].Value.Trim();
                option.Description = m.Groups["desc"].Value.Trim();
                option.Value       = (int)Math.Pow(2, index++);

                optionList.Add(option);
            }

            context.EnumDesc.Options = optionList;
        }
        public override void Interpret(EnumDescContext context)
        {
            if (context == null || string.IsNullOrWhiteSpace(context.EnumHtml))
            {
                return;
            }

            //枚举描述的匹配正则式
            Regex regex = new Regex(@"<(?<HxTag>h\d+)\s+[^>]*id=""枚举[^>]+>\s*\[枚举\]\s*(?<desc>[^\((]+)[\((](?<name>[^\))]+)[\))]</\k<HxTag>>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            Match match = regex.Match(context.EnumHtml);

            string name       = match.Groups["name"].Value;
            int    splitIndex = name.IndexOf("_");
            string module     = splitIndex > 0 ? name.Substring(0, splitIndex) : name;

            if (string.IsNullOrWhiteSpace(name))
            {
                name = ConfigurationManager.AppSettings["DefaultModuleName"];
            }

            context.EnumDesc.Name        = name.Replace("_", "");              //枚举名称
            context.EnumDesc.Description = match.Groups["desc"].Value;         //枚举说明
            context.EnumDesc.Module      = module;                             //所属模块
        }