/// <summary>
/// 命名方式转换
/// </summary>
public static class NameStyleConvert
{
/// <summary>
/// 从ab_cd到AbCd
/// </summary>
/// <param name="name">属性名或字段名</param>
/// <returns></returns>
public static string F_TC(string name)
{
return Regex.Replace(name, "(^|_)[a-z]", new MatchEvaluator(M_TC));
}
/// <summary>
/// 从ab_cd到abCd
/// </summary>
/// <param name="name">属性名或字段名</param>
/// <returns></returns>
public static string F_Tc(string name)
{
return Regex.Replace(name, "_[a-z]", new MatchEvaluator(M_TC));
}
/// <summary>
/// 从AbCd或abCd到ab_cd
/// </summary>
/// <param name="name">属性名或字段名</param>
/// <returns></returns>
public static string FCT_(string name)
{
return Regex.Replace(name, "[A-Z]", new MatchEvaluator(MCT_));
}
private static string M_TC(Match m)
{
if (m.Index == 0)
{
return m.Value.ToUpper();
}
return m.Value.ToUpper().Substring(1);
}
private static string MCT_(Match m)
{
if (m.Index == 0)
{
return m.Value.ToLower();
}
return "_" + m.Value.ToLower();
}
}
C#命名方式转换代码
最新推荐文章于 2022-06-02 11:45:35 发布