Exemplo n.º 1
0
        /// <summary>
        /// 执行文法解释
        /// </summary>
        /// <param name="context"></param>
        public override void Interpret(EntityClassResolveContext context)
        {
            if (context == null || context.TableDesc == null)
            {
                return;
            }

            Regex regex = new Regex(@"<(?<foreach>ForEach_Properties)>(?<template>((?!<separator>).|\n)*)<separator>(?<separator>((?!</separator>).|\n)*)</separator>[^<]*</\k<foreach>>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string text = context.OutputEntityClassContent;

            MatchCollection mc = regex.Matches(text);

            //遍历处理匹配结果的解析
            foreach (Match m in mc)
            {
                //获取当前匹配结果中的属性模板
                var propertyTemplate = m.Groups["template"].Value;

                //分隔器
                var separator = m.Groups["separator"].Value;

                //获取当前匹配结果解析后的code内容
                var data = GetTemplateReplaceAfterChars(propertyTemplate, separator, context.TableDesc.Columns);

                text = text.Replace(m.Value, data);
            }

            //实体对象输出内容
            context.OutputEntityClassContent = text;
        }
        public override void Interpret(EntityClassResolveContext context)
        {
            if (context == null || context.TableDesc == null)
            {
                return;
            }

            Regex regex = new Regex(@"<(?<foreach>ForEach_PrimaryKeys)>(?<template>((?!<separator>).|\n)*)<separator>(?<separator>((?!</separator>).|\n)*)</separator></\k<foreach>>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string text = context.OutputEntityClassContent;

            MatchCollection mc = regex.Matches(text);

            //主键集合
            var primaryKeyslist = context.TableDesc.Columns.Where(p => p.IsPrimaryKey == true).ToList();

            foreach (Match m in mc)
            {
                //当前匹配结果中的主键模板
                string template = m.Groups["template"].Value;

                //分隔器
                string separator = m.Groups["separator"].Value;

                //获取当前匹配结果解析后的code内容
                var data = GetTemplateReplaceAfterChars(template, separator, primaryKeyslist);

                text = text.Replace(m.Value, data);
            }

            //实体对象输出内容
            context.OutputEntityClassContent = text;
        }
Exemplo n.º 3
0
        /// <summary>
        /// 执行文法解释
        /// </summary>
        /// <param name="context"></param>
        public override void Interpret(EntityClassResolveContext context)
        {
            if (context == null || context.TableDesc == null)
            {
                return;
            }

            Regex regex = new Regex(@"\{Entity_Description\}", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string text = context.OutputEntityClassContent;

            context.OutputEntityClassContent = regex.Replace(text, context.TableDesc.Description);
        }