{"id":13629657,"url":"https://github.com/iiweis/PrimitiveStaticDataGenerator","last_synced_at":"2025-04-17T09:35:35.453Z","repository":{"id":215749400,"uuid":"338462579","full_name":"iiweis/PrimitiveStaticDataGenerator","owner":"iiweis","description":"C# Source Generator for creating methods that return optimized ReadOnlySpan\u003cT\u003e static data from primitive values.","archived":false,"fork":false,"pushed_at":"2022-06-18T04:05:05.000Z","size":32,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-01T22:44:06.818Z","etag":null,"topics":["csharp","csharp-sourcegenerator"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iiweis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-02-13T00:05:42.000Z","updated_at":"2024-01-22T21:52:35.000Z","dependencies_parsed_at":"2024-01-07T21:54:21.412Z","dependency_job_id":null,"html_url":"https://github.com/iiweis/PrimitiveStaticDataGenerator","commit_stats":null,"previous_names":["iiweis/primitivestaticdatagenerator"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iiweis%2FPrimitiveStaticDataGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iiweis%2FPrimitiveStaticDataGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iiweis%2FPrimitiveStaticDataGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iiweis%2FPrimitiveStaticDataGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iiweis","download_url":"https://codeload.github.com/iiweis/PrimitiveStaticDataGenerator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751348,"owners_count":17196619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","csharp-sourcegenerator"],"created_at":"2024-08-01T22:01:15.819Z","updated_at":"2024-11-08T20:31:39.111Z","avatar_url":"https://github.com/iiweis.png","language":"C#","readme":"# PrimitiveStaticDataGenerator\n\n[![Nuget](https://img.shields.io/nuget/v/PrimitiveStaticDataGenerator?color=1f6feb)](https://www.nuget.org/packages/PrimitiveStaticDataGenerator)\n\n\u003e [!NOTE]\n\u003e This library was created at a time when optimization using ReadOnlySpan for constant arrays had the limitation that it did not apply to primitive types that are not single byte.\n\u003e \n\u003e Since this restriction has been removed by the support of dotnet/roslyn#61414, there is little point in using this library in .NET 7 and later environments.\u003cbr\u003e\n\u003e For more information on dotnet/roslyn#61414, check out [Performance Improvements in .NET 8 | Initialization](https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-8/#initialization). \n\n## Usage\n\n### user code\n```cs\nusing System;\nusing PrimitiveStaticDataGenerator;\n\nnamespace MyCode\n{\n    public partial class UserClass\n    {\n        [return: PrimitiveStaticData(1, 2, 3, 4, 5)]\n        public static partial ReadOnlySpan\u003cint\u003e Int();\n        \n        [return: PrimitiveStaticData('A', 'B', 'C')]\n        public static partial ReadOnlySpan\u003cchar\u003e Char();\n    }\n}\n```\n\n### generated code(example)\n\n\u003cdetails\u003e\n\u003csummary\u003eMyCode.UserClass.Char.cs\u003c/summary\u003e\n\n```cs\nusing System;\nusing PrimitiveStaticDataGenerator;\nusing System.Runtime.InteropServices;\nusing System.Runtime.CompilerServices;\n\nnamespace MyCode\n{\n    public partial class UserClass\n    {\n        public static partial ReadOnlySpan\u003cchar\u003e Char()\n        {\n            ReadOnlySpan\u003cbyte\u003e span;\n            if (BitConverter.IsLittleEndian)\n            {\n                span = new byte[]\n                {\n                    65,\n                    0,\n                    66,\n                    0,\n                    67,\n                    0\n                };\n            }\n            else\n            {\n                span = new byte[]\n                {\n                    0,\n                    65,\n                    0,\n                    66,\n                    0,\n                    67\n                };\n            }\n\n            return MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As\u003cbyte, char\u003e(ref MemoryMarshal.GetReference(span)), 3);\n        }\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eMyCode.UserClass.Int.cs\u003c/summary\u003e\n\n```cs\nusing System;\nusing PrimitiveStaticDataGenerator;\nusing System.Runtime.InteropServices;\nusing System.Runtime.CompilerServices;\n\nnamespace MyCode\n{\n    public partial class UserClass\n    {\n        public static partial ReadOnlySpan\u003cint\u003e Int()\n        {\n            ReadOnlySpan\u003cbyte\u003e span;\n            if (BitConverter.IsLittleEndian)\n            {\n                span = new byte[]\n                {\n                    1,\n                    0,\n                    0,\n                    0,\n                    2,\n                    0,\n                    0,\n                    0,\n                    3,\n                    0,\n                    0,\n                    0,\n                    4,\n                    0,\n                    0,\n                    0,\n                    5,\n                    0,\n                    0,\n                    0\n                };\n            }\n            else\n            {\n                span = new byte[]\n                {\n                    0,\n                    0,\n                    0,\n                    1,\n                    0,\n                    0,\n                    0,\n                    2,\n                    0,\n                    0,\n                    0,\n                    3,\n                    0,\n                    0,\n                    0,\n                    4,\n                    0,\n                    0,\n                    0,\n                    5\n                };\n            }\n\n            return MemoryMarshal.CreateReadOnlySpan(ref Unsafe.As\u003cbyte, int\u003e(ref MemoryMarshal.GetReference(span)), 5);\n        }\n    }\n}\n```\n\u003c/details\u003e\n\n## Supported Types\n- bool\n- char\n- sbyte\n- byte\n- short\n- ushort\n- int\n- uint\n- long\n- ulong\n- float\n- double\n- string\n","funding_links":[],"categories":["Source Generators","Do not want to test 112 ( old ISourceGenerator )"],"sub_categories":["Other","1. [ThisAssembly](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiiweis%2FPrimitiveStaticDataGenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiiweis%2FPrimitiveStaticDataGenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiiweis%2FPrimitiveStaticDataGenerator/lists"}