using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace Ant.ORM
{
public static class StringExtension
{
///
/// 在SQL语句后面追加注释
///
/// 需追加注释的SQL语句
/// 作者
/// SQL的功能描述
/// SQL所在的文件名
/// SQL所在的方法名
/// 添加注释后的SQL
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);
}
///
/// 在SQL语句后面追加注释
///
///
/// 需追加注释的SQL语句
///
///
/// 评论注释
///
///
/// 添加注释后的SQL
///
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;
}
///
/// 插入Sql评论
///
public class SqlComment
{
///
/// 作者
///
public string Author { get; set; }
///
/// 用途
///
public string ForUse { get; set; }
///
/// 文件名
///
public string FileName { get; set; }
///
/// 函数名
///
public string FunName { get; set; }
///
/// 是否是测试
///
public static bool IsTest { get; set; }
///
/// 项目名称
///
public string ProjectName { get; set; }
}
}
}