123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- namespace Ant.ORM
- {
- public static class StringExtension
- {
- /// <summary>
- /// 在SQL语句后面追加注释
- /// </summary>
- /// <param name="sql">需追加注释的SQL语句</param>
- /// <param name="author">作者</param>
- /// <param name="forUse">SQL的功能描述</param>
- /// <param name="fileName">SQL所在的文件名</param>
- /// <param name="funName">SQL所在的方法名</param>
- /// <returns>添加注释后的SQL</returns>
- private static string SqlAppendComment(this string sql,
- string author, string forUse, string fileName, string funName, string projectname)
- {
- if (author == null)
- {
- throw new ArgumentNullException("author参数为null或空字符串");
- }
- if (string.IsNullOrEmpty(forUse))
- {
- throw new ArgumentNullException("forUse参数为null或空字符串");
- }
- if (string.IsNullOrEmpty(fileName))
- {
- throw new ArgumentNullException("fileName参数为null或空字符串");
- }
- if (string.IsNullOrEmpty(funName))
- {
- throw new ArgumentNullException("funName参数为null或空字符串");
- }
- return
- string.Format(
- @"{0}
- --Flat:{5}/Author:{1}/For:{2}/File:{3}/Fun:{4}",
- sql,
- author,
- forUse,
- fileName,
- funName,
- projectname);
- }
- /// <summary>
- /// 在SQL语句后面追加注释
- /// </summary>
- /// <param name="sql">
- /// 需追加注释的SQL语句
- /// </param>
- /// <param name="comment">
- /// 评论注释
- /// </param>
- /// <returns>
- /// 添加注释后的SQL
- /// </returns>
- public static string AppendComment(this string sql,
- SqlComment comment)
- {
- if (!SqlComment.IsTest)
- {
- return sql.SqlAppendComment(comment.Author, comment.ForUse, comment.FileName, comment.FunName,comment.ProjectName);
- }
- return sql;
- }
- /// <summary>
- /// 插入Sql评论
- /// </summary>
- public class SqlComment
- {
- /// <summary>
- /// 作者
- /// </summary>
- public string Author { get; set; }
- /// <summary>
- /// 用途
- /// </summary>
- public string ForUse { get; set; }
- /// <summary>
- /// 文件名
- /// </summary>
- public string FileName { get; set; }
- /// <summary>
- /// 函数名
- /// </summary>
- public string FunName { get; set; }
- /// <summary>
- /// 是否是测试
- /// </summary>
- public static bool IsTest { get; set; }
- /// <summary>
- /// 项目名称
- /// </summary>
- public string ProjectName { get; set; }
- }
- }
- }
|