Basmus.Parametrization
1.0.5
dotnet add package Basmus.Parametrization --version 1.0.5
NuGet\Install-Package Basmus.Parametrization -Version 1.0.5
<PackageReference Include="Basmus.Parametrization" Version="1.0.5" />
<PackageVersion Include="Basmus.Parametrization" Version="1.0.5" />
<PackageReference Include="Basmus.Parametrization" />
paket add Basmus.Parametrization --version 1.0.5
#r "nuget: Basmus.Parametrization, 1.0.5"
#:package Basmus.Parametrization@1.0.5
#addin nuget:?package=Basmus.Parametrization&version=1.0.5
#tool nuget:?package=Basmus.Parametrization&version=1.0.5
Basmus.Parametrization
A lightweight .NET library that enables parameter extraction directly from C# interpolated strings using FormattableString
, eliminating the need for separate parameter mapping structures.
Features
- Direct parameter extraction from interpolated strings without additional value-placeholder mapping
- Zero-parsing approach using native
System.FormattableString
- Supports both named and positional parameterization
- Processes nested interpolation strings
- Provides full control on placeholder formatting by
PlaceholderBuilder
- name conflict resolving
- name auto generation
Installation
dotnet add package Basmus.Parametrization
Quick Start
The ParameterHelper
class is the main entry point for parameter extraction. It provides two simple methods for working with interpolated strings.
Named Parameterization
var id = 1;
var name = "John";
var date = DateTime.Now;
FormattableString fs = $"User {name.AsParameter("name")} with ID {id.AsParameter("id")} was created on {date.AsParameter()}";
// Original: User John with ID 1 was created on 18.04.2025 15:54:16
var parameters = ParameterHelper.Parametrize(fs, new MyNamedPlaceholderBuilder());
// Parametrized: User @name with ID @id was created on @p0
// Parameters:
// @name: John
// @id: 1
// @p0: 18.04.2025 15:54:16
Positional Parameterization
var id = 1;
var name = "John";
FormattableString fs = $"User {name.AsParameter()} with ID {id.AsParameter()}";
// Original: User John with ID 1
var parameters = ParameterHelper.Parametrize(fs, new MyPositionalPlaceholderBuilder());
// Parametrized: User $0 with ID $1
// Parameters:
// [0]: John
// [1]: 1
Performance
The library has been benchmarked for different parameter set sizes with both Named and Positional parametrizers.
Named Parametrizer
Method | Mean | Allocated |
---|---|---|
'1000 parameters' | 342.670 μs | 169.86 KB |
'100 parameters' | 38.295 μs | 17.12 KB |
'10 parameters' | 4.668 μs | 2.19 KB |
Positional Parametrizer
Method | Mean | Allocated |
---|---|---|
'1000 parameters' | 236.895 μs | 102.72 KB |
'100 parameters' | 25.677 μs | 10.36 KB |
'10 parameters' | 3.241 μs | 1.09 KB |
License
This project is licensed under the MIT License - see the LICENSE file for details.
Copyright © 2025 Basmus
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
-
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.5 | 160 | 5/1/2025 |