Menu

Stop Writing .Trim() in Every Controller: Building AutoNormalize for Modern .NET
📰

Stop Writing .Trim() in Every Controller: Building AutoNormalize for Modern .NET

DEV Community: dotnet·surya pratap singh·14 days ago
#R9nzvhL0
#devtodotnet#devto#dev#string#autonormalize
Long article (1113 words) — no AI summary yet.
Reading 0:00
15s threshold

How many times have you reviewed a pull request in ASP.NET Core and spotted something like this?

var email = request . Email ? . Trim ( ) ; var firstName = string . IsNullOrWhiteSpace ( request . FirstName ) ? null : request . FirstName . Trim ( ) ;

Enter fullscreen mode

Exit fullscreen mode

Across enterprise .NET codebases, input canonicalization is often treated as an afterthought. It gets scattered across controllers, MediatR handlers, FluentValidation transform rules, and repository methods.

Inevitably, someone forgets a .Trim() on an endpoint:

"[email protected] " and "[email protected]" end up as duplicate accounts in your database.

An empty input "" is stored instead of a clean database NULL , breaking SQL NULL semantics.

Decomposed Unicode characters cause string equality comparisons to mysteriously fail.

To solve this, developers often reach for a global JsonConverter<string> .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.