forked from efcore/EFCore.NamingConventions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Proper Snake Case for issue efcore#151
- Loading branch information
Showing
7 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,6 @@ public enum NamingConvention | |
LowerCase, | ||
CamelCase, | ||
UpperCase, | ||
UpperSnakeCase | ||
UpperSnakeCase, | ||
ProperSnakeCase | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
EFCore.NamingConventions/Internal/ProperSnakeCaseNameRewriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text; | ||
|
||
namespace EFCore.NamingConventions.Internal; | ||
|
||
public class ProperSnakeCaseNameRewriter : SnakeCaseNameRewriter | ||
{ | ||
private readonly CultureInfo _culture; | ||
|
||
public ProperSnakeCaseNameRewriter(CultureInfo culture) : base(culture) | ||
=> _culture = culture; | ||
|
||
public override string RewriteName(string name) | ||
{ | ||
if (string.IsNullOrEmpty(name)) | ||
{ | ||
return name; | ||
} | ||
|
||
name = base.RewriteName(name); | ||
|
||
var arr = name.ToCharArray(); | ||
var shouldCapitalizeNext = true; | ||
|
||
for (var i = 0; i < arr.Length; i++) | ||
{ | ||
if (arr[i] == '_') | ||
{ | ||
shouldCapitalizeNext = true; | ||
} | ||
else if (shouldCapitalizeNext) | ||
{ | ||
arr[i] = char.ToUpper(arr[i]); | ||
shouldCapitalizeNext = false; | ||
} | ||
} | ||
|
||
return new(arr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters