docs/v3-namespace-migration.md
This document provides guidance on migrating code from Humanizer v2 to v3, focusing on the namespace consolidation changes.
For the full
2.14.1 -> 3.0.8upgrade path (all breaking changes, package/tooling changes, patch-line fixes, and known regressions), see migration-v3.md.
Humanizer v3 consolidates all sub-namespaces into the root Humanizer namespace. This is a source-breaking change that requires code updates.
All of the following namespaces have been moved into Humanizer:
Humanizer.BytesHumanizer.LocalisationHumanizer.Localisation.FormattersHumanizer.Localisation.NumberToWordsHumanizer.DateTimeHumanizeStrategyHumanizer.ConfigurationHumanizer.Localisation.DateToOrdinalWordsHumanizer.Localisation.OrdinalizersHumanizer.InflectionsHumanizer.Localisation.CollectionFormattersHumanizer.Localisation.TimeToClockNotationBefore (v2):
using Humanizer.Bytes;
using Humanizer.Localisation;
using Humanizer.Configuration;
public class Example
{
public void Method()
{
var size = ByteSize.FromKilobytes(10);
var formatter = new DefaultFormatter("en-US");
Configurator.Localisation = new CultureInfo("en-US");
}
}
After (v3):
using Humanizer;
public class Example
{
public void Method()
{
var size = ByteSize.FromKilobytes(10);
var formatter = new DefaultFormatter("en-US");
Configurator.Localisation = new CultureInfo("en-US");
}
}
Humanizer v3 includes a Roslyn analyzer that automatically detects and fixes namespace usage. No separate installation is required—the analyzer is bundled with the Humanizer.Core package starting from v3.0.0.
Once you have installed or updated to Humanizer.Core v3.0.0 or later, the analyzer will be available automatically in your project.
The package includes Roslyn-versioned analyzer assets, so modern .NET SDK/Visual Studio toolchains load a compatible analyzer automatically. You should not need to add manual System.* package references to make the analyzer load.
If you are on 3.0.1 and see analyzer load warnings (for example AD0001) with older SDK/Visual Studio toolchains, upgrade to 3.0.8 and see the analyzer/patch-fix sections in migration-v3.md.
Ctrl+. (Windows/Linux) / Cmd+. (Mac)The analyzer runs automatically during build and reports warnings:
# Build and see warnings
dotnet build
# Apply automatic fixes using dotnet format
dotnet format analyzers --diagnostics HUMANIZER001
If you prefer to migrate manually or can't use the analyzer:
Search your codebase for using directives:
# Using grep
grep -r "using Humanizer\." . --include="*.cs" | grep -v "using Humanizer;"
# Using PowerShell
Get-ChildItem -Recurse -Filter *.cs | Select-String "using Humanizer\." | Where-Object { $_ -notmatch "using Humanizer;" }
Replace all old namespace usings with:
using Humanizer;
If you use fully qualified names in your code, update them:
Before:
var size = Humanizer.Bytes.ByteSize.FromKilobytes(10);
After:
var size = Humanizer.ByteSize.FromKilobytes(10);
// Or with using directive:
using Humanizer;
// ...
var size = ByteSize.FromKilobytes(10);
After migration, rebuild and test your application:
dotnet build
dotnet test
Before:
using Humanizer.Bytes;
using Humanizer.Localisation;
using Humanizer.Configuration;
using Humanizer.Inflections;
After:
using Humanizer;
Before:
using Humanizer;
using Humanizer.Bytes;
using Humanizer.Localisation;
After:
using Humanizer;
Before:
public Humanizer.Bytes.ByteSize GetFileSize(string path)
{
var info = new FileInfo(path);
return Humanizer.Bytes.ByteSize.FromBytes(info.Length);
}
After:
public Humanizer.ByteSize GetFileSize(string path)
{
var info = new FileInfo(path);
return Humanizer.ByteSize.FromBytes(info.Length);
}
// Or better with using:
using Humanizer;
public ByteSize GetFileSize(string path)
{
var info = new FileInfo(path);
return ByteSize.FromBytes(info.Length);
}
If you get compiler errors after migration, ensure:
using Humanizer; at the top of your fileIf the analyzer doesn't show warnings:
dotnet clean && dotnet build)If you can't use the Roslyn analyzer (e.g., older IDE, build system limitations):
Humanizer.Analyzers for automatic detection and fixingusing Humanizer;Humanizer namespace