Jacobi.Formatters
1.0.0
dotnet add package Jacobi.Formatters --version 1.0.0
NuGet\Install-Package Jacobi.Formatters -Version 1.0.0
<PackageReference Include="Jacobi.Formatters" Version="1.0.0" />
<PackageVersion Include="Jacobi.Formatters" Version="1.0.0" />
<PackageReference Include="Jacobi.Formatters" />
paket add Jacobi.Formatters --version 1.0.0
#r "nuget: Jacobi.Formatters, 1.0.0"
#:package Jacobi.Formatters@1.0.0
#addin nuget:?package=Jacobi.Formatters&version=1.0.0
#tool nuget:?package=Jacobi.Formatters&version=1.0.0
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
O ⇒ Object
E ⇒ Enum
| 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 | Versions 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. |
-
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 |