FormattableSb 1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FormattableSb --version 1.0.0
NuGet\Install-Package FormattableSb -Version 1.0.0
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="FormattableSb" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FormattableSb --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FormattableSb, 1.0.0"
#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 FormattableSb as a Cake Addin #addin nuget:?package=FormattableSb&version=1.0.0 // Install FormattableSb as a Cake Tool #tool nuget:?package=FormattableSb&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FormattableSb
A mutable FormattableString:
var firstDayOfSummer = new DateTime(2022, 6, 21);
var lastDayOfSummer = new DateTime(2022, 9, 23);
var sqlBuilder = new FormattableStringBuilder()
.AppendInterpolated($"INSERT INTO dbo.VacationDates (Date)")
.AppendLine()
.AppendInterpolated($"VALUES");
for (var date = firstDayOfSummer; date <= lastDayOfSummer; date = date.AddDays(1))
{
sqlBuilder
.AppendLine()
.AppendInterpolated($"({date})");
if (date != lastDayOfSummer)
{
sqlBuilder.AppendInterpolated($",");
}
}
// sql.GetArguments():
// [
// System.DateTime,
// System.DateTime,
// ...
// ]
// sql.Format:
// INSERT INTO dbo.VacationDates (Date)
// VALUES
// ({0}),
// ({1}),
// ...
var sql = sqlBuilder.ToFormattableString();
Usage with EF Core:
using var context = new VacationingContext();
context.Database.ExecuteSqlInterpolated(sql);
Features:
- Adheres to the C# language specification
- Preservres aligment and format strings
API:
AppendInterpolated:
/// <summary>
/// Appends the specified interpolated string to the end of the composite format string,
/// replacing its arguments with placeholders and adding them as objects.
/// </summary>
/// <param name="handler">The interpolated string to append, along with the arguments.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
public FormattableStringBuilder AppendInterpolated([InterpolatedStringHandlerArgument("")] AppendInterpolatedHandler handler)
AppendLine:
/// <summary>
/// Appends the default line terminator to the end of the composite format string.
/// </summary>
/// <returns>A reference to this instance after the append operation has completed.</returns>
public FormattableStringBuilder AppendLine()
Setup:
- Install FormattableSb via NuGet Package Manager, Package Manager Console or dotnet CLI:
Install-Package FormattableSb
dotnet add package FormattableSb
Credits:
- Thanks to Stephen Toub for the implementation
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net6.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 |
---|---|---|
2.0.19 | 68 | 11/14/2024 |
2.0.18 | 69 | 11/13/2024 |
2.0.17 | 1,232 | 11/17/2023 |
2.0.16 | 188 | 9/2/2023 |
2.0.15 | 150 | 9/2/2023 |
2.0.14 | 189 | 7/3/2023 |
2.0.13 | 179 | 7/1/2023 |
2.0.12 | 152 | 5/31/2023 |
2.0.11 | 202 | 4/7/2023 |
2.0.10 | 226 | 3/9/2023 |
2.0.9 | 227 | 3/9/2023 |
2.0.8 | 236 | 3/9/2023 |
2.0.7 | 322 | 1/19/2023 |
2.0.6 | 303 | 12/31/2022 |
2.0.5 | 308 | 12/23/2022 |
2.0.4 | 309 | 12/15/2022 |
2.0.3 | 328 | 11/26/2022 |
2.0.2 | 329 | 11/26/2022 |
2.0.1 | 396 | 10/21/2022 |
2.0.0 | 393 | 10/15/2022 |
1.0.5 | 387 | 10/5/2022 |
1.0.4 | 385 | 10/1/2022 |
1.0.3 | 404 | 9/28/2022 |
1.0.2 | 403 | 9/27/2022 |
1.0.1 | 427 | 9/27/2022 |
1.0.0 | 398 | 9/27/2022 |