NamingStrategyConverter 1.2.0
dotnet add package NamingStrategyConverter --version 1.2.0
NuGet\Install-Package NamingStrategyConverter -Version 1.2.0
<PackageReference Include="NamingStrategyConverter" Version="1.2.0" />
<PackageVersion Include="NamingStrategyConverter" Version="1.2.0" />
<PackageReference Include="NamingStrategyConverter" />
paket add NamingStrategyConverter --version 1.2.0
#r "nuget: NamingStrategyConverter, 1.2.0"
#:package NamingStrategyConverter@1.2.0
#addin nuget:?package=NamingStrategyConverter&version=1.2.0
#tool nuget:?package=NamingStrategyConverter&version=1.2.0
NamingStrategyConverter.NET
An open source, dead simple naming strategy converter library for .NET. Dependency free, no inheritance, no reflection, no magic. Just KISS conversions.
The following naming strategies are currently supported:
- PascalCase
- camelCase
- snake_case
- kebab-case
- UPPER_SNAKE_CASE
- UPPER-KEBAB-CASE
- dot.case
Usage
NamingStrategyConverter.NET exposes string extension methods for each naming strategy following a ToXCase()
syntax. For example, to convert to camelCase, you can use the ToCamelCase()
method. Going from any naming strategy to another is supported.
string str = "thisWasCamelCase";
Console.WriteLine(str.ToSnakeCase());
// output: this_was_camel_case
Console.WriteLine(str.ToPascalCase());
// output: ThisWasCamelCase
Console.WriteLine(str.ToUpperKebabCase());
// output: THIS-WAS-CAMEL-CASE
You can optionally pass in the input naming strategy for a more optimal conversion for improved performance when applicable. In certain scenarios, the conversions can be done with zero memory allocation.
str.ToSnakeCase(NamingStrategy.CamelCase);
Each naming strategy also has an IsXCase()
method that returns a boolean about whether the input follows that naming strategy.
Console.WriteLine(str.IsCamelCase());
// output: true
Console.WriteLine(str.IsSnakeCase());
// output: false
System.Text.Json
JsonNamingPolicy
implementations for all our converters are available to use with System.Text.Json
for json
property name conversion. This can be used in conjunction with the JsonSerializerOptions
class to configure the
naming policy for serialization and deserialization.
using DanWalsh.NamingStrategyConverter.SystemTextJson;
var options = new JsonSerializerOptions
{
PropertyNamingPolicy = new SnakeCaseNamingPolicy()
};
var json = JsonSerializer.Serialize(new { MyProperty = "value" }, options);
Console.WriteLine(json);
// output: {"my_property":"value"}
Contribute
We greatly appreciate contributions from the community. We welcome any performance enhancements, bug corrections, or the introduction of new naming strategies. If you have such contributions, kindly submit a PR for our evaluation. It's worth noting that every naming strategy in this project comes with its own set of unit tests. Thus, when introducing a new strategy, we ask that you include comprehensive tests for each conversion from one strategy to another. Additionally, if you're proposing performance improvements, kindly confirm that you've conducted benchmark tests to verify the efficacy of your suggested changes.
License
NamingStrategyConverter.NET is open source and freely available under the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NamingStrategyConverter:
Package | Downloads |
---|---|
NamingStrategyConverter.SystemTextJson
System.Text.Json extension for NamingStrategyConverter |
GitHub repositories
This package is not used by any popular GitHub repositories.