添加全局转换实体属性名方法

This commit is contained in:
stulzq
2019-06-13 14:42:48 +08:00
parent 04547c06f8
commit d54ebf3a04
3 changed files with 174 additions and 31 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()));
}
}
}