Exemplo n.º 1
0
        /// <summary>
        /// 根据名称获取SQL(或视图)语句 (已经处理过注释,和参数替换的内容)
        /// </summary>
        /// <param name="key"></param>
        /// <param name="stringFormatValues">如果需要格式化大括号参数</param>
        /// <returns></returns>
        public static string GetCode(string key, params object[] stringFormatValues)
        {
            if (!string.IsNullOrEmpty(key))
            {
                Dictionary <string, string> fileList = FileList;
                if (fileList.ContainsKey(key))
                {
                    string text = fileList[key];

                    if (text.Contains(":\\"))
                    {
                        text = FileExtend.ReadAllText(text);
                        int index = text.LastIndexOf("/*");
                        if (index > -1)//去掉注释
                        {
                            text = Regex.Replace(text, @"/\*[.\s\S]*?\*/", string.Empty, RegexOptions.IgnoreCase);
                        }
                    }
                    text = text.Trim();
                    if (stringFormatValues.Length > 0)
                    {
                        text = string.Format(text, stringFormatValues);
                    }
                    text = FormatPara(text.Trim());      //去掉空格
                    if (key[0] == 'V' && text[0] != '(') //补充语法
                    {
                        text = "(" + text + ") " + key;
                    }

                    //参数化格式
                    return(text);
                }
            }
            return(key);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 根据名称获取原始的SQL(或视图)语句
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 internal static string GetSourceCode(string key)
 {
     if (!string.IsNullOrEmpty(key))
     {
         string[] files = Directory.GetFiles(path, key + ".sql", SearchOption.AllDirectories);
         if (files != null && files.Length > 0)
         {
             return(FileExtend.ReadAllText(files[0]));
         }
     }
     return(string.Empty);
 }