GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - ufcpp/StringLiteralGenerator: C# Source Generator for UTF-8 binary literal

BranchesTags
Open more actions menu

Latest commit

 

History

80 Commits
80 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
samples
samples
 
 
src/StringLiteralGenerator
src/StringLiteralGenerator
 
 
.editorconfig
.editorconfig
 
 
.gitignore
.gitignore
 
 
Directory.Build.props
Directory.Build.props
 
 
LICENSE
LICENSE
 
 
StringLiteralGenerator.sln
StringLiteralGenerator.sln
 
 
readme.md
readme.md
 
 

Repository files navigation

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

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>

About

C# Source Generator for UTF-8 binary literal

Topics

csharp-sourcegenerator

Resources

Readme
MIT license
Activity

Stars

146 stars

Watchers

4 watching

Forks

3 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.