-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for optional naming methods
- Loading branch information
1 parent
7752443
commit ea75cf6
Showing
4 changed files
with
78 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Json.Pointer; | ||
|
||
public class PointerCreationOptions | ||
{ | ||
private PropertyNameResolver? _propertyNameResolver; | ||
|
||
public static PointerCreationOptions Default = new(); | ||
|
||
public PropertyNameResolver? PropertyNameResolver | ||
{ | ||
get => _propertyNameResolver ??= PropertyNameResolvers.AsDeclared; | ||
set => _propertyNameResolver = value; | ||
} | ||
} |
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,46 @@ | ||
using System.Reflection; | ||
using Humanizer; | ||
|
||
namespace Json.Pointer; | ||
|
||
/// <summary> | ||
/// Declares a property name resolution which is used to provide a property name. | ||
/// </summary> | ||
/// <param name="input">The property.</param> | ||
/// <returns>The property name</returns> | ||
public delegate string PropertyNameResolver(MemberInfo input); | ||
|
||
/// <summary> | ||
/// Defines a set of predefined property name resolution methods. | ||
/// </summary> | ||
public static class PropertyNameResolvers | ||
{ | ||
/// <summary> | ||
/// Makes no changes. Properties are generated with the name of the property in code. | ||
/// </summary> | ||
public static readonly PropertyNameResolver AsDeclared = x => x.Name; | ||
/// <summary> | ||
/// Property names to camel case (e.g. `camelCase`). | ||
/// </summary> | ||
public static readonly PropertyNameResolver CamelCase = x => x.Name.Camelize(); | ||
/// <summary> | ||
/// Property names to pascal case (e.g. `PascalCase`). | ||
/// </summary> | ||
public static readonly PropertyNameResolver PascalCase = x => x.Name.Pascalize(); | ||
/// <summary> | ||
/// Property names to snake case (e.g. `Snake_Case`). | ||
/// </summary> | ||
public static readonly PropertyNameResolver SnakeCase = x => x.Name.Underscore(); | ||
/// <summary> | ||
/// Property names to upper snake case (e.g. `UPPER_SNAKE_CASE`). | ||
/// </summary> | ||
public static readonly PropertyNameResolver UpperSnakeCase = x => x.Name.Underscore().ToUpperInvariant(); | ||
/// <summary> | ||
/// Property names to kebab case (e.g. `Kebab-Case`). | ||
/// </summary> | ||
public static readonly PropertyNameResolver KebabCase = x => x.Name.Kebaberize(); | ||
/// <summary> | ||
/// Property names to upper kebab case (e.g. `UPPER-KEBAB-CASE`). | ||
/// </summary> | ||
public static readonly PropertyNameResolver UpperKebabCase = x => x.Name.Kebaberize().ToUpperInvariant(); | ||
} |