All Projects → pCYSl5EDgo → EmbeddingResourceCSharp

pCYSl5EDgo / EmbeddingResourceCSharp

Licence: MIT license
Embed resource files more C# programmer friendly!

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to EmbeddingResourceCSharp

WinFormsComInterop
ComWrappers required to run NativeAOT and WinForms
Stars: ✭ 54 (+145.45%)
Mutual labels:  csharp-sourcegenerator
JsonSrcGen
Json library that uses .NET 5 Source Generators
Stars: ✭ 140 (+536.36%)
Mutual labels:  csharp-sourcegenerator
Immutype
Immutability is easy!
Stars: ✭ 26 (+18.18%)
Mutual labels:  csharp-sourcegenerator
dotvariant
A type-safe and space-efficient sum type for C# (comparable to discriminated unions in C or C++)
Stars: ✭ 52 (+136.36%)
Mutual labels:  csharp-sourcegenerator
ThisAssembly
Exposes project and assembly level information as constants in the ThisAssembly class using source generators powered by Roslyn.
Stars: ✭ 209 (+850%)
Mutual labels:  csharp-sourcegenerator
JsonByExampleGenerator
Generate classes based on example json files in your project. Uses a C# 9 source generator.
Stars: ✭ 55 (+150%)
Mutual labels:  csharp-sourcegenerator
Vogen
A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Stars: ✭ 240 (+990.91%)
Mutual labels:  csharp-sourcegenerator
spreadcheetah
SpreadCheetah is a high-performance .NET library for generating spreadsheet (Microsoft Excel XLSX) files.
Stars: ✭ 107 (+386.36%)
Mutual labels:  csharp-sourcegenerator
AutoInterface
C# interface-to-member source generator
Stars: ✭ 47 (+113.64%)
Mutual labels:  csharp-sourcegenerator
DpdtInject
Highly efficient compile-time general purpose DI container based on C# source generators.
Stars: ✭ 25 (+13.64%)
Mutual labels:  csharp-sourcegenerator
avatar
A modern compile-time generated interception/proxy library
Stars: ✭ 80 (+263.64%)
Mutual labels:  csharp-sourcegenerator
StringLiteralGenerator
C# Source Generator for UTF-8 binary literal
Stars: ✭ 109 (+395.45%)
Mutual labels:  csharp-sourcegenerator
GitBuildInfo.SourceGenerator
Source Generator for dumping the git branch information, commit hash, and if the working tree is dirty or clean on projects that install this and applies them as an assembly level attribute.
Stars: ✭ 15 (-31.82%)
Mutual labels:  csharp-sourcegenerator
TypedSignalR.Client
C# Source Generator to Create Strongly Typed SignalR Client.
Stars: ✭ 16 (-27.27%)
Mutual labels:  csharp-sourcegenerator
StructPacker
Low-level, lightweight and performance-focused serializer for C# struct types that uses Source Generators technology.
Stars: ✭ 42 (+90.91%)
Mutual labels:  csharp-sourcegenerator
GraphQL.Tools
GraphQL.Tools is a GraphQL to C# compiler (code-generator) which turns your GraphQL schema into a set of C# classes, interfaces, and enums.
Stars: ✭ 49 (+122.73%)
Mutual labels:  csharp-sourcegenerator
Plastic
This project provides encapsulation of things like Domain, Application Rules, Business Rules or Business Logic in Application.
Stars: ✭ 30 (+36.36%)
Mutual labels:  csharp-sourcegenerator
Generator.Equals
A source code generator for automatically implementing IEquatable<T> using only attributes.
Stars: ✭ 49 (+122.73%)
Mutual labels:  csharp-sourcegenerator
GodotOnReady
A C# Source Generator that adds convenient onready-like features to your C# scripts in Godot Mono without any reflection.
Stars: ✭ 73 (+231.82%)
Mutual labels:  csharp-sourcegenerator

EmbedResourceCSharp

This is a C# Source Generator. This let you embed files in your application. You do not need to use Assembly.GetManifestResourceStream anymore.

How to use

Install

dotnet add package EmbedResourceCSharp

Add only 1 package to your C# project.

Embedding file

Provide that there are some files like below.

  • projectFolder/
    • Example.csproj
    • ExampleProgram.cs
    • resourceFileA.txt
namespace Example
{
    // partial methods require partial class/struct!
    public partial class ExampleClass
    {
        /*
            The relative file path from C# project folder should be specified.
            The return value type must be System.ReadOnlySpan<byte>.
            No parameter must exist.
            The method must be static and partial.
            The accessibility of the method does not matter.
        */
        [EmbedResourceCSharp.FileEmbed("resourceFileA.txt")]
        private static partial System.ReadOnlySpan<byte> GetFileContentA();
    }
}

You can get file content byte sequence with static partial method System.ReadOnlySpan<byte> GetFileContentA.

Embedding files under specific folder

Provide that there are some files like below.

  • projectFolder/
    • Example2.csproj
    • ExampleProgram.cs
  • folderB/
    • resourceA.txt
    • resourceB.txt
    • folderB_C/
      • resourceC.txt
    • resourceD.csv
namespace Example2
{
    // partial methods require partial class/struct!
    public partial class ExampleClass
    {
        /*
            The relative folder path from C# project folder should be specified. The folder path should end with slash or backslash.
            The return value type must be System.ReadOnlySpan<byte>.
            One parameter must exist and its type must be System.ReadOnlySpan<char>. The parameter name does not matter.
            The method must be static and partial.
            The accessibility of the method does not matter.
        */
        [EmbedResourceCSharp.FolderEmbed("../folderB/", "*.txt")]
        private static partial System.ReadOnlySpan<byte> GetResouceFileContent(System.ReadOnlySpan<char> path);

        public static void Main()
        {
            // Specify relative path from the folder.
            var aContent = GetResouceFileContent("resourceA.txt");
            var bContent = GetResouceFileContent("resourceB.txt");
            var cContent = GetResouceFileContent("folderB_C/resourceC.txt");
            // var dContent = GetResouceFileContent("resourceD.csv");
            // Above method call throws an FileNotFoundException!
        }
    }
}

You can include all files under the target folder recursively. You can filter file with search pattern.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].