DimonSmart.StringTrimmerGenerator 1.0.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package DimonSmart.StringTrimmerGenerator --version 1.0.1                
NuGet\Install-Package DimonSmart.StringTrimmerGenerator -Version 1.0.1                
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="DimonSmart.StringTrimmerGenerator" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DimonSmart.StringTrimmerGenerator --version 1.0.1                
#r "nuget: DimonSmart.StringTrimmerGenerator, 1.0.1"                
#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.
// Install DimonSmart.StringTrimmerGenerator as a Cake Addin
#addin nuget:?package=DimonSmart.StringTrimmerGenerator&version=1.0.1

// Install DimonSmart.StringTrimmerGenerator as a Cake Tool
#tool nuget:?package=DimonSmart.StringTrimmerGenerator&version=1.0.1                

StringTrimmerGenerator

Don't ever rely on user input! This package offers the ability to trim every string in a class. Sanitizing input data before processing is beneficial.

NOTE1: There is a StringTrimmer package with provide similar functionality The difference is:

  • StringTrimmer - reflection based
  • StringTrimmerGenerator - use Source Generator to provide best performance

NOTE2: StringTrimmerGenerator support trim operation over all public strings and public class properties for classes marked with [GenerateStringTrimmer] attribute

Problem statement

Standard class for describing a user.

public class User
{
   public string Name {get; set;}
   public string Surname {get; set;}
   public string Secondname {get; set;}
   public string UserName {get; set;}
   public string Email {get; set;}
   public string Phone {get; set;}
}

Usage of the User class to add a new User record to the database is typical.

Can you find an error?

Try 
public void CreateUser (User user)
{
   user.Name = user.Name.Trim();
   user.Surname = user.Surname.Trim();
   user.Secondname = user.Secondname.Trim();
   user.Email = user.Email.Trim();
   user.Phone = user.Phone.Trim();
}

Error: UserName Trim command is missing. Due to the tiny difference in UserName, this allows for many users while having only one real user.

  • "John Doe "
  • " John Doe"
  • " John Doe "
  • "John Doe"

Having the same user registered many times irritates the support personnel!

Note: It is usual for users to not merely input a UserName during registration, but to copy it from other sources with different spaces surrounding (and inside) the name.

Magic bullet! (Usage example)

Try 
public void CreateUser (CreateUserRequest request)
{
   request.TrimAll(); // Just one line
}
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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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.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.2 218 3/18/2023
1.0.1 290 12/26/2022
1.0.0 287 12/25/2022