forked from sebastienros/fluid
-
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.
Fixing benchmarks and introducing MemberAccessStrategy (sebastienros#143
- Loading branch information
1 parent
2408a59
commit b7bd73b
Showing
9 changed files
with
105 additions
and
9 deletions.
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
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
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,54 @@ | ||
using System.Reflection; | ||
using System.Text; | ||
|
||
namespace Fluid | ||
{ | ||
public class MemberNameStrategies | ||
{ | ||
public static readonly MemberNameStrategy Default = RenameDefault; | ||
public static readonly MemberNameStrategy CamelCase = RenameCamelCase; | ||
public static readonly MemberNameStrategy SnakeCase = RenameCamelCase; | ||
|
||
private static string RenameDefault(MemberInfo member) => member.Name; | ||
|
||
public static string RenameCamelCase(MemberInfo member) | ||
{ | ||
var name = member.Name; | ||
var firstChar = name[0]; | ||
|
||
if (firstChar == char.ToLowerInvariant(firstChar)) | ||
{ | ||
return name; | ||
} | ||
|
||
return char.ToLowerInvariant(firstChar) + name.Substring(1); | ||
} | ||
|
||
public static string RenameSnake(MemberInfo member) | ||
{ | ||
var builder = new StringBuilder(); | ||
var name = member.Name; | ||
var previousUpper = false; | ||
|
||
for (var i = 0; i < name.Length; i++) | ||
{ | ||
var c = name[i]; | ||
if (char.IsUpper(c)) | ||
{ | ||
if (i > 0 && !previousUpper) | ||
{ | ||
builder.Append("_"); | ||
} | ||
builder.Append(char.ToLowerInvariant(c)); | ||
previousUpper = true; | ||
} | ||
else | ||
{ | ||
builder.Append(c); | ||
previousUpper = false; | ||
} | ||
} | ||
return builder.ToString(); | ||
} | ||
} | ||
} |
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,6 @@ | ||
using System.Reflection; | ||
|
||
namespace Fluid | ||
{ | ||
public delegate string MemberNameStrategy(MemberInfo member); | ||
} |
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