Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ufcpp/StringLiteralGenerator
C# Source Generator for UTF-8 binary literal
https://github.com/ufcpp/StringLiteralGenerator
csharp-sourcegenerator
Last synced: 3 months ago
JSON representation
C# Source Generator for UTF-8 binary literal
- Host: GitHub
- URL: https://github.com/ufcpp/StringLiteralGenerator
- Owner: ufcpp
- License: mit
- Created: 2020-06-10T11:28:29.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-03-22T03:56:15.000Z (over 2 years ago)
- Last Synced: 2024-06-22T05:03:53.983Z (5 months ago)
- Topics: csharp-sourcegenerator
- Language: C#
- Homepage:
- Size: 72.3 KB
- Stars: 132
- Watchers: 5
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- RSCG_Examples - https://github.com/ufcpp/StringLiteralGenerator
- csharp-source-generators - StringLiteralGenerator - ![stars](https://img.shields.io/github/stars/ufcpp/StringLiteralGenerator?style=flat-square&cacheSeconds=604800) ![last commit](https://img.shields.io/github/last-commit/ufcpp/StringLiteralGenerator?style=flat-square&cacheSeconds=86400) for optimizing UTF-8 binaries. (Source Generators / Other)
README
# C# StringLiteralGenerator
A C# [Source Generator](https://github.com/dotnet/roslyn/blob/master/docs/features/source-generators.md) for optimizing UTF-8 binaries.
Original source (manually written):
```cs
namespace Sample
{
partial class Literals
{
[StringLiteral.Utf8Attribute("aαあ😊")]
public static partial System.ReadOnlySpan S();
}
}
```Generated source:
```cs
namespace Sample
{
partial class Literals
{
public static partial System.ReadOnlySpan 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](https://vcsjones.dev/2019/02/01/csharp-readonly-span-bytes-static/)## NuGet
[![NuGet](https://img.shields.io/nuget/v/StringLiteralGenerator?style=flat-square)](https://www.nuget.org/packages/StringLiteralGenerator)
```xml
Exe
net5.0
```
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:
```xml
Exe
net5.0
```