예제 #1
0
        public override void Interpret(MappingResolveContext context)
        {
            if (context == null || context.Table == null)
            {
                return;
            }

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

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

            //单个字段代码的生成模板
            string columnTemplate = match.Groups["template"].Value;

            //分隔符
            string separator = match.Groups["separator"].Value;

            StringBuilder replaceChars = new StringBuilder();

            foreach (var column in context.Table.Columns)
            {
                string columnCode = ResolvColumn(columnTemplate, column);

                if (replaceChars.Length > 0)
                {
                    replaceChars.Append(separator);
                }

                replaceChars.Append(columnCode);
            }

            //输出替换

            context.Output = regex.Replace(context.Output, replaceChars.ToString());
        }
예제 #2
0
        public override void Interpret(MappingResolveContext context)
        {
            if (context == null || context.Table == null)
            {
                return;
            }

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

            string text = context.Output;

            context.Output = regex.Replace(text, context.Table.Module);
        }
        public override void Interpret(MappingResolveContext context)
        {
            if (context == null || context.Table == null)
            {
                return;
            }

            Regex regex = new Regex(@"<If_PrimaryKeys_None>(?<keysnone>((?!<ElseIf_PrimaryKeys_One>).|\n)*)<ElseIf_PrimaryKeys_One>(?<keysone>((?!<ElseIf_PrimaryKeys_More>).|\n)*)<ElseIf_PrimaryKeys_More>(?<keysmore>((?!</EndIf>).|\n)*)</EndIf>", RegexOptions.IgnoreCase | RegexOptions.Compiled);

            string text = context.Output;

            Match match = regex.Match(text);

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

            //主键数量
            int keysCount = primaryKeys.Count();

            //主键生成的模板,根据主键数量不同,有不同的模板
            string template = "";

            if (keysCount == 0)
            {
                template = match.Groups["keysnone"].Value;
            }
            else if (keysCount == 1)
            {
                template = match.Groups["keysone"].Value;
            }
            else if (keysCount > 1)
            {
                template = match.Groups["keysmore"].Value;
            }

            //定义一个主键解析上下文
            KeysResolveStrategyContext resolveContext = new KeysResolveStrategyContext(keysCount);
            string replaceChars = resolveContext.Execute(template, primaryKeys);

            //输出主键的生成代码字符串内容
            context.Output = regex.Replace(text, replaceChars);
        }
예제 #4
0
        public override void Interpret(MappingResolveContext context)
        {
            if (context == null || context.Table == null)
            {
                return;
            }

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

            string text = context.Output;

            string schema = context.Table.Schema;

            if (string.IsNullOrWhiteSpace(schema))
            {
                schema = "dbo";
            }

            context.Output = regex.Replace(text, schema);
        }