Merge pull request #60 from stulzq/master

添加全局转换实体属性名方法
This commit is contained in:
2881099
2019-06-13 14:49:01 +08:00
committed by GitHub
3 changed files with 153 additions and 2 deletions

View File

@ -0,0 +1,45 @@
namespace FreeSql.Internal
{
public enum StringConvertType
{
/// <summary>
/// 不进行任何处理
/// </summary>
None = 0,
/// <summary>
/// 将帕斯卡命名字符串转换为下划线分隔字符串
/// <para></para>
/// BigApple -> Big_Apple
/// </summary>
PascalCaseToUnderscore,
/// <summary>
/// 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全大写
/// <para></para>
/// BigApple -> BIG_APPLE
/// </summary>
PascalCaseToUnderscoreWithUpper,
/// <summary>
/// 将帕斯卡命名字符串转换为下划线分隔字符串,且转换为全小写
/// <para></para>
/// BigApple -> big_apple
/// </summary>
PascalCaseToUnderscoreWithLower,
/// <summary>
/// 将字符串转换为大写
/// <para></para>
/// BigApple -> BIGAPPLE
/// </summary>
Upper,
/// <summary>
/// 将字符串转换为小写
/// <para></para>
/// BigApple -> bigapple
/// </summary>
Lower
}
}

View File

@ -0,0 +1,20 @@
using System.Linq;
namespace FreeSql.Internal
{
public static class StringUtils
{
/// <summary>
/// 将帕斯卡命名字符串转换为下划线分隔字符串
/// <para></para>
/// BigApple -> Big_Apple
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string PascalCaseToUnderScore(string str)
{
return string.Concat(str.Select((x, i) =>
i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString()));
}
}
}