Basmus.Parametrization 1.0.5

dotnet add package Basmus.Parametrization --version 1.0.5
                    
NuGet\Install-Package Basmus.Parametrization -Version 1.0.5
                    
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="Basmus.Parametrization" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Basmus.Parametrization" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Basmus.Parametrization" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Basmus.Parametrization --version 1.0.5
                    
#r "nuget: Basmus.Parametrization, 1.0.5"
                    
#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.
#:package Basmus.Parametrization@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Basmus.Parametrization&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Basmus.Parametrization&version=1.0.5
                    
Install as a Cake Tool

Basmus.Parametrization

NuGet Tests License: MIT

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

Details

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

Details

License

This project is licensed under the MIT License - see the LICENSE file for details.

Copyright © 2025 Basmus

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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