-
-
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.
Merge pull request #545 from gregsdennis/pointer/expression-last-and-…
…naming-options Extended JSON Pointer support
- Loading branch information
Showing
7 changed files
with
190 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace Json.Pointer; | ||
|
||
/// <summary> | ||
/// Options for creating pointers using <see cref="JsonPointer.Create{T}(Expression{Func{T, object}}, PointerCreationOptions)"/>. | ||
/// </summary> | ||
public class PointerCreationOptions | ||
{ | ||
private PropertyNameResolver? _propertyNameResolver; | ||
|
||
/// <summary> | ||
/// Default settings. | ||
/// </summary> | ||
public static readonly PointerCreationOptions Default = new(); | ||
|
||
/// <summary> | ||
/// Gets or sets the property naming resolver. Default is <see cref="PropertyNameResolvers.AsDeclared"/>. | ||
/// </summary> | ||
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(); | ||
} |
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