Skip to content

Repository files navigation

C# StringLiteralGenerator

A C# Source Generator for optimizing UTF-8 binaries.

Original source (manually written):

namespaceSample{partialclassLiterals{[StringLiteral.Utf8Attribute("aαあ😊")]publicstaticpartialSystem.ReadOnlySpan<byte>S();}}

Generated source:

namespaceSample{partialclassLiterals{publicstaticpartialSystem.ReadOnlySpan<byte>S()=>newbyte[]{97,206,177,227,129,130,240,159,152,138,};}}

NuGet

NuGet

<ProjectSdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReferenceInclude="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:

<ProjectSdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReferenceInclude="StringLiteralGenerator"Version="1.0.0-preiew" />
<PackageReferenceInclude="Microsoft.Net.Compilers.Toolset"Version="3.8.0-4.final"PrivateAssets="all" />
</ItemGroup>
</Project>

About

C# Source Generator for UTF-8 binary literal

Topics

Resources

Stars

146 stars

Watchers

4 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages