StringLiteralGenerator
C# Source Generator for UTF-8 binary literal
Install / Use
/learn @ufcpp/StringLiteralGeneratorREADME
C# StringLiteralGenerator
A C# Source Generator for optimizing UTF-8 binaries.
Original source (manually written):
namespace Sample
{
partial class Literals
{
[StringLiteral.Utf8Attribute("aαあ😊")]
public static partial System.ReadOnlySpan<byte> S();
}
}
Generated source:
namespace Sample
{
partial class Literals
{
public static partial System.ReadOnlySpan<byte> S() => new byte[] {97, 206, 177, 227, 129, 130, 240, 159, 152, 138, };
}
}
- Generates UTF-8 binary data from string literals (UTF-16).
- The UTF-8 data is optimized to avoid allocation. see: C# ReadOnlySpan and static data
NuGet
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StringLiteralGenerator" Version="1.0.0" />
</ItemGroup>
</Project>
For versions earlier than .NET 5 SDK RC2 you may also need to add a reference to Microsoft.Net.Compilers.Toolset.
So the csproj may look like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="StringLiteralGenerator" Version="1.0.0-preiew" />
<PackageReference Include="Microsoft.Net.Compilers.Toolset" Version="3.8.0-4.final" PrivateAssets="all" />
</ItemGroup>
</Project>
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
