SimpleTextTemplate.Contexts 1.0.0

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

// Install SimpleTextTemplate.Contexts as a Cake Tool
#tool nuget:?package=SimpleTextTemplate.Contexts&version=1.0.0                

SimpleTextTemplate

Build(.NET) NuGet SimpleTextTemplate package in DotNet feed in Azure Artifacts

シンプルなテキストテンプレートエンジンです。

説明

SimpleTextTemplateは、識別子の置換のみに対応したテキストテンプレートエンジンです。

インストール

ライブラリ名 説明
SimpleTextTemplate テンプレートの解析及びレンダリングを行います。
SimpleTextTemplate.Abstractions SimpleTextTemplateの抽象化です。
SimpleTextTemplate.Contexts テンプレートのレンダリングで使用するコンテキストの作成を行います。
SimpleTextTemplate.Generator コンパイル時にテンプレートの解析を行うソースジェネレーターです。

NuGet(正式リリース版)

dotnet add package SimpleTextTemplate
dotnet add package SimpleTextTemplate.Contexts
dotnet add package SimpleTextTemplate.Generator

Azure Artifacts(開発用ビルド)

dotnet add package SimpleTextTemplate -s https://pkgs.dev.azure.com/finphie/Main/_packaging/DotNet/nuget/v3/index.json
dotnet add package SimpleTextTemplate.Contexts -s https://pkgs.dev.azure.com/finphie/Main/_packaging/DotNet/nuget/v3/index.json
dotnet add package SimpleTextTemplate.Generator -s https://pkgs.dev.azure.com/finphie/Main/_packaging/DotNet/nuget/v3/index.json

使い方

次の例では、外部のライブラリであるCommunityToolkit.HighPerformanceを参照しています。

SimpleTextTemplate

using System;
using System.Text;
using CommunityToolkit.HighPerformance.Buffers;
using SimpleTextTemplate;
using SimpleTextTemplate.Contexts;
using Utf8Utility;

var symbols = new Utf8ArrayDictionary<Utf8Array>();
symbols.TryAdd((Utf8Array)"Identifier", (Utf8Array)"Hello, World!");

using var bufferWriter = new ArrayPoolBufferWriter<byte>();
var source = Encoding.UTF8.GetBytes("{{ Identifier }}");
var template = Template.Parse(source);
template.Render(bufferWriter, Context.Create(symbols));

// Hello, World!
Console.WriteLine(Encoding.UTF8.GetString(bufferWriter.WrittenSpan));

SimpleTextTemplate.Generator

using System;
using System.Text;
using CommunityToolkit.HighPerformance.Buffers;
using SimpleTextTemplate;

var context = new SampleContext(Encoding.UTF8.GetBytes("Hello, World!"));

using var bufferWriter = new ArrayPoolBufferWriter<byte>();
ZTemplate.Render(bufferWriter, context);

// Hello, World!
Console.WriteLine(Encoding.UTF8.GetString(bufferWriter.WrittenSpan));

readonly record struct SampleContext(byte[] Identifier);

static partial class ZTemplate
{
    // TemplateAttributeまたはTemplateFileAttributeでテンプレート文字列を指定してください。
    [Template("{{ Identifier }}")]
    public static partial void Render(IBufferWriter<byte> bufferWriter, SampleContext context);
}

サンプルプロジェクト

ベンチマーク

レンダリング

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19043.1526 (21H1/May2021Update)
AMD Ryzen 7 5800U with Radeon Graphics, 1 CPU, 16 logical and 8 physical cores
.NET SDK=6.0.200-preview.22055.15
  [Host]   : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT
  .NET 6.0 : .NET 6.0.2 (6.0.222.6406), X64 RyuJIT

Job=.NET 6.0  Runtime=.NET 6.0  
Method Mean Error StdDev Ratio RatioSD Gen 0 Gen 1 Allocated
SimpleTextTemplate 89.95 ns 0.674 ns 0.631 ns 1.45 0.01 0.0105 - 88 B
SimpleTextTemplateUtf8 74.41 ns 0.201 ns 0.188 ns 1.20 0.01 0.0095 - 80 B
SimpleTextTemplateSourceGenerator 71.16 ns 0.377 ns 0.352 ns 1.14 0.01 0.0105 - 88 B
SimpleTextTemplateSourceGeneratorUtf8 62.16 ns 0.359 ns 0.336 ns 1.00 0.00 0.0095 - 80 B
Scriban 10,026.03 ns 19.977 ns 18.686 ns 161.31 0.87 3.6469 0.3204 30,542 B
ScribanLiquid 8,569.52 ns 35.784 ns 31.721 ns 137.92 0.78 3.9368 0.3662 32,952 B
Regex 107.15 ns 0.510 ns 0.477 ns 1.72 0.01 0.0057 - 48 B

ベンチマークプロジェクト

サポートフレームワーク

  • .NET 6

作者

finphie

ライセンス

MIT

クレジット

このプロジェクトでは、次のライブラリ等を使用しています。

ライブラリ

テスト

アナライザー

ベンチマーク

その他

Product 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.

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
3.0.0 72 11/17/2024
2.1.0 1,084 2/10/2024
2.0.0 2,224 11/15/2023
1.1.0 243 3/18/2023
1.0.1 629 2/22/2022
1.0.0 417 2/22/2022
0.6.0 473 1/14/2022
0.5.0 493 10/17/2021
0.4.0 413 9/4/2021
0.3.0 446 8/29/2021
0.2.0 1,935 6/4/2021
0.1.0 373 5/16/2021