NamingStrategyConverter 1.2.0

dotnet add package NamingStrategyConverter --version 1.2.0
                    
NuGet\Install-Package NamingStrategyConverter -Version 1.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NamingStrategyConverter" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NamingStrategyConverter" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="NamingStrategyConverter" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NamingStrategyConverter --version 1.2.0
                    
#r "nuget: NamingStrategyConverter, 1.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NamingStrategyConverter@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NamingStrategyConverter&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=NamingStrategyConverter&version=1.2.0
                    
Install as a Cake Tool

NamingStrategyConverter.NET

Build Release Nuget Nuget

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last Updated
1.2.0 172 10/25/2024
1.1.0 522 6/15/2023
1.0.0 217 6/15/2023