SimpleTextTemplate.Contexts
1.1.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 SimpleTextTemplate.Contexts --version 1.1.0
NuGet\Install-Package SimpleTextTemplate.Contexts -Version 1.1.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.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SimpleTextTemplate.Contexts --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: SimpleTextTemplate.Contexts, 1.1.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.1.0 // Install SimpleTextTemplate.Contexts as a Cake Tool #tool nuget:?package=SimpleTextTemplate.Contexts&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
SimpleTextTemplate
シンプルなテキストテンプレートエンジンです。
説明
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.Buffers;
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では、テンプレート文字列を指定してください。
[Template("{{ Identifier }}")]
public static partial void Render(IBufferWriter<byte> bufferWriter, SampleContext context);
// TemplateFileAttributeでは、指定されたファイルを解析します。
// 相対パスを指定した場合、プロジェクトファイルが存在するディレクトリが基準となります。
// 基準ディレクトリを変更する場合は、プロジェクトファイルで次のように設定します。
// <PropertyGroup>
// <SimpleTextTemplatePath></SimpleTextTemplatePath>
// </PropertyGroup>
// [TemplateFile("template.txt")]
// 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
クレジット
このプロジェクトでは、次のライブラリ等を使用しています。
ライブラリ
- CommunityToolkit.HighPerformance
- Humanizer.Core
- Microsoft.CodeAnalysis.Analyzers
- Microsoft.CodeAnalysis.CSharp.Workspaces
- Utf8Utility
テスト
- FluentAssertions
- Microsoft.NET.Test.Sdk
- Newtonsoft.Json
- NuGet.Frameworks
- xunit
- xunit.runner.visualstudio
アナライザー
- Microsoft.CodeAnalysis.NetAnalyzers (SDK組み込み)
- Microsoft.VisualStudio.Threading.Analyzers
- StyleCop.Analyzers
ベンチマーク
- BenchmarkDotNet
- CommandLineParser
- Iced
- Microsoft.CodeAnalysis.CSharp
- Microsoft.Diagnostics.NETCore.Client
- Microsoft.Diagnostics.Runtime
- Microsoft.Diagnostics.Tracing.TraceEvent
- Perfolizer
- Scriban
その他
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
- SimpleTextTemplate.Abstractions (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.