Jacobi.Formatters 1.0.0

dotnet add package Jacobi.Formatters --version 1.0.0
                    
NuGet\Install-Package Jacobi.Formatters -Version 1.0.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="Jacobi.Formatters" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Jacobi.Formatters" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Jacobi.Formatters" />
                    
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 Jacobi.Formatters --version 1.0.0
                    
#r "nuget: Jacobi.Formatters, 1.0.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 Jacobi.Formatters@1.0.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=Jacobi.Formatters&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Jacobi.Formatters&version=1.0.0
                    
Install as a Cake Tool

Object and Enum Formatter

Typically the object's ToString() value is used as a basis for further formatting. For Enums and [Flags] there are some exceptions.

Formats

Object.To<FormatterType>()

Enum.Option.To<FormatterType>()

String Formatters

OObject EEnum

Formatter Type Types Description Example Result
Upper O/E Converts all to upper case. 'Upper' 'UPPER'
Lower O/E Converts all to lower case. 'Lower' 'lower'
CamelCase O/E Converts to first char to lower. 'CamelCase' 'camelCase'
KebabCase O/E Inserts a '-' before every capital char. 'KebabCase' 'Kebab-Case'
SnakeCase O/E Inserts a '_' before every capital char. 'SnakeCase' 'Snake_Case'
SpaceCase O/E Inserts a ' ' before every capital char. 'SpaceCase' 'Space Case'
Humanized O/E Separates words and lowers every capital. 'HumanizedCase' 'Humanized case'
NumericValue E Decimal value as string Option1 = 1 '1'
HexValue E Hexadecimal value as string Option1 = 1 '0x1'
HexValue2 E Hexadecimal value as string Option1 = 1 '0x01'
HexValue4 E Hexadecimal value as string Option1 = 1 '0x0001'
HexValue8 E Hexadecimal value as string Option1 = 1 '0x00000001'

Code Attribute Enum-Formatters

When the specific Attribute is not found on the Enum-option, it's default ToString() value is returned.

Formatter Type Attribute Description Example Result
Description System.ComponentModel.DescriptionAttribute Returns the Description of the attribute. [Description("This description")] 'This Description'
Display System.ComponentModel.DataAnnotations.DisplayAttribute Returns either the Description, Name, ShortName or GroupName of the attribute* [Display(Name="MyName")] 'MyName'
DefaultValue System.ComponentModel.DefaultValueAttribute Retrieves the value from the attribute and uses its string representation. [DefaultValue(42)] '42'
NameOf<T> T Uses Reflection on the Attribute T and retrieves the Name property. [SomeAttribute(Name="MyName")] 'MyName'
DescriptionOf<T> T Uses Reflection on the Attribute T and retrieves the Description property. [SomeAttribute(Description="This description")] 'This description'

*) To-Be-Determined how to format the string if multiple fields are filled.

Note that NameOf<T> and DescriptionOf<T> use reflection and will perform less good.

Extensibility

You can write your own formatters by implementing the (static) interface IFormatter and / or IEnumFormatter.

Here is an example of the CamelCase implementation. It implements both interfaces (IEnumFormatter is implemented explicitly) and performs the logic on the ToString() value.

public sealed class CamelCase : IFormatter, IEnumFormatter
{
    private CamelCase() { }

    public static string Format<T>(T value)
    {
        var str = value?.ToString() ?? String.Empty;
        return new([Char.ToLowerInvariant(str[0]), .. str[1..]]);
    }

    static string IEnumFormatter.Format<T>(T value)
        => Format<T>(value);
}

Refer to the source code for more examples.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 350 11/17/2025