{"id":13629411,"url":"https://github.com/pCYSl5EDgo/EmbeddingResourceCSharp","last_synced_at":"2025-04-17T09:33:35.665Z","repository":{"id":118306780,"uuid":"310797693","full_name":"pCYSl5EDgo/EmbeddingResourceCSharp","owner":"pCYSl5EDgo","description":"Embed resource files more C# programmer friendly!","archived":false,"fork":false,"pushed_at":"2024-06-04T13:23:36.000Z","size":92,"stargazers_count":66,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-08-01T22:43:39.293Z","etag":null,"topics":["csharp","csharp-sourcegenerator","dotnet"],"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/pCYSl5EDgo.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-07T08:11:40.000Z","updated_at":"2024-07-23T14:15:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"4a48e4af-d71b-4981-8386-e32924351502","html_url":"https://github.com/pCYSl5EDgo/EmbeddingResourceCSharp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pCYSl5EDgo%2FEmbeddingResourceCSharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pCYSl5EDgo%2FEmbeddingResourceCSharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pCYSl5EDgo%2FEmbeddingResourceCSharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pCYSl5EDgo%2FEmbeddingResourceCSharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pCYSl5EDgo","download_url":"https://codeload.github.com/pCYSl5EDgo/EmbeddingResourceCSharp/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223751092,"owners_count":17196567,"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","dotnet"],"created_at":"2024-08-01T22:01:09.735Z","updated_at":"2024-11-08T20:30:51.545Z","avatar_url":"https://github.com/pCYSl5EDgo.png","language":"C#","funding_links":[],"categories":["Content"],"sub_categories":["27. [EmbedResourceCSharp](https://ignatandrei.github.io/RSCG_Examples/v2/docs/EmbedResourceCSharp) , in the [FilesToCode](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#filestocode) category"],"readme":"# EmbedResourceCSharp\r\n\r\nThis is a [C# Source Generator](https://devblogs.microsoft.com/dotnet/new-c-source-generator-samples/).\r\nThis let you embed files in your application.\r\nYou do not need to use `Assembly.GetManifestResourceStream` anymore.\r\n\r\n# How to use\r\n\r\n## Install\r\n\r\n```sh\r\ndotnet add package EmbedResourceCSharp\r\n```\r\n\r\nAdd only 1 package to your C# project.\r\n\r\n## Embedding file\r\n\r\nProvide that there are some files like below.\r\n\r\n- projectFolder/\r\n  - Example.csproj\r\n  - ExampleProgram.cs\r\n  - resourceFileA.txt\r\n\r\n```csharp\r\nnamespace Example\r\n{\r\n    // partial methods require partial class/struct!\r\n    public partial class ExampleClass\r\n    {\r\n        /*\r\n            The relative file path from C# project folder should be specified.\r\n            The return value type must be System.ReadOnlySpan\u003cbyte\u003e.\r\n            No parameter must exist.\r\n            The method must be static and partial.\r\n            The accessibility of the method does not matter.\r\n        */\r\n        [EmbedResourceCSharp.FileEmbed(\"resourceFileA.txt\")]\r\n        private static partial System.ReadOnlySpan\u003cbyte\u003e GetFileContentA();\r\n    }\r\n}\r\n```\r\n\r\nYou can get file content byte sequence with static partial method `System.ReadOnlySpan\u003cbyte\u003e GetFileContentA`.\r\n\r\n## Embedding files under specific folder\r\n\r\nProvide that there are some files like below.\r\n\r\n- projectFolder/\r\n  - Example2.csproj\r\n  - ExampleProgram.cs\r\n- folderB/\r\n  - resourceA.txt\r\n  - resourceB.txt\r\n  - folderB_C/\r\n    - resourceC.txt\r\n  - resourceD.csv\r\n\r\n```csharp\r\nnamespace Example2\r\n{\r\n    // partial methods require partial class/struct!\r\n    public partial class ExampleClass\r\n    {\r\n        /*\r\n            The relative folder path from C# project folder should be specified. The folder path should end with slash or backslash.\r\n            The return value type must be System.ReadOnlySpan\u003cbyte\u003e.\r\n            One parameter must exist and its type must be System.ReadOnlySpan\u003cchar\u003e. The parameter name does not matter.\r\n            The method must be static and partial.\r\n            The accessibility of the method does not matter.\r\n        */\r\n        [EmbedResourceCSharp.FolderEmbed(\"../folderB/\", \"*.txt\")]\r\n        private static partial System.ReadOnlySpan\u003cbyte\u003e GetResouceFileContent(System.ReadOnlySpan\u003cchar\u003e path);\r\n\r\n        public static void Main()\r\n        {\r\n            // Specify relative path from the folder.\r\n            var aContent = GetResouceFileContent(\"resourceA.txt\");\r\n            var bContent = GetResouceFileContent(\"resourceB.txt\");\r\n            var cContent = GetResouceFileContent(\"folderB_C/resourceC.txt\");\r\n            // var dContent = GetResouceFileContent(\"resourceD.csv\");\r\n            // Above method call throws an FileNotFoundException!\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nYou can include all files under the target folder recursively.\r\nYou can filter file with search pattern.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FpCYSl5EDgo%2FEmbeddingResourceCSharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FpCYSl5EDgo%2FEmbeddingResourceCSharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FpCYSl5EDgo%2FEmbeddingResourceCSharp/lists"}