{"id":17888078,"url":"https://github.com/fireflycons/firefly.embeddedresourceloader","last_synced_at":"2025-04-03T02:42:28.994Z","repository":{"id":96974368,"uuid":"288263019","full_name":"fireflycons/Firefly.EmbeddedResourceLoader","owner":"fireflycons","description":"Embedded Resource Loader with a difference!","archived":false,"fork":false,"pushed_at":"2021-12-24T14:47:22.000Z","size":166,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T12:40:26.181Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/fireflycons.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-08-17T19:00:13.000Z","updated_at":"2023-03-30T09:09:29.000Z","dependencies_parsed_at":null,"dependency_job_id":"9566ad30-6adf-4b91-81d0-1142bcf5c9ad","html_url":"https://github.com/fireflycons/Firefly.EmbeddedResourceLoader","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FFirefly.EmbeddedResourceLoader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FFirefly.EmbeddedResourceLoader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FFirefly.EmbeddedResourceLoader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fireflycons%2FFirefly.EmbeddedResourceLoader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fireflycons","download_url":"https://codeload.github.com/fireflycons/Firefly.EmbeddedResourceLoader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927809,"owners_count":20856193,"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":[],"created_at":"2024-10-28T13:36:30.007Z","updated_at":"2025-04-03T02:42:28.972Z","avatar_url":"https://github.com/fireflycons.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firefly.EmbeddedResourceLoader\n\n[![Build status](https://ci.appveyor.com/api/projects/status/9faegqir2x2mtccx/branch/master?svg=true)](https://ci.appveyor.com/project/fireflycons/firefly-embeddedresourceloader/branch/master)\n\n![Nuget](https://img.shields.io/nuget/v/Firefly.EmbeddedResourceLoader)\n\n## About\n\nYet another library for managing embedded resources? Well yes, however this one does it using attributes.\n\nI find that I use embedded resources a lot when creating unit tests, and I tire of writing the same old boilerplate to locate embedded resources and load their content into test class members.\nThis library provides a mechanism to simply add an attribute to any field or property of a class that refers to an embedded resource, and either via inheritance from a base class provided here\nor a call to a static method in this library, all attributed members will be initialized with embedded resource content.\n\n## Types that can be auto-intialized\n\nOut of the box the following can easily be initialized\n\n* `string` - directly from any text resource\n* Stream constructed types - Any object that has a single argument constructor of type `Stream`, e.g. `System.Drawing.Bitmap`\n* Stream loaded types - Any object that has a static or instance `Load` method taking a single argument of type `Stream` or `StreamReader`, e.g. `XDocument` or `YamlDotNet.RepresentationModel.YamlStream`\n* Parse types - Any object that has a static `Parse` method taking a single argument of type `string`, e.g. `Newtonsoft.Json.Linq.JObject` or `Newtonsoft.Json.Linq.JArray`\n\nThere is also a plugin system discussed in more detail in the [documentation](https://fireflycons.github.io/Firefly-EmbeddedResourceLoader/articles/plugins.html) that allows you to define how an object of any type not covered by the above can be loaded with embedded resource data.\n\n## Examples\n\nIn all the following examples, the embedded resources are expected to be present in the assembly where the class decorated with the `EmbeddedResource` attribute is declared.\nOther constructors of the attribute take an assembly name or an `Assembly` object that specifices the assembly in which to search for the resource.\n\nIn this example, all resources are automatically loaded when an instance of the class is created. Static members are only initialized the first time.\n\n```csharp\npublic class ResourceLoadedClass: AutoResourceLoader\n{\n\t[EmbeddedResource('FirstString.txt')]\n\tprivate static string FirstString;\n\n\t[EmbeddedResource('XmlDocument.xml')]\n\tpublic XDocument Document { get; set; }\n}\n```\n\nIn this example resources are loaded when requested by the code\n\n```csharp\npublic class ResourceLoadedClass\n{\n\t[EmbeddedResource('FirstString.txt')]\n\tprivate static string FirstString;\n\n\t[EmbeddedResource('XmlDocument.xml')]\n\tpublic XDocument Document { get; set; }\n}\n\n...\n\nvar c = new ResourceLoadedClass();\n\nResourceLoader.LoadResources(c);\n```\n\nAnd for entirely static classes...\n\n```csharp\npublic static class StaticResourceLoadedClass\n{\n\t[EmbeddedResource('FirstString.txt')]\n\tprivate static string FirstString;\n\n\t[EmbeddedResource('XmlDocument.xml')]\n\tpublic static XDocument Document { get; set; }\n}\n\n...\n\nResourceLoader.LoadResources(typeof(StaticResourceLoadedClass));\n```\n\nMaterializing a file...\n\n\n```csharp\npublic class FileLoadingClass: AutoResourceLoader, IDisposable\n{\n\t[EmbeddedResource('XmlDocument.xml')]\n\tprivate TempFile myFile { get; set; }\n\n\tvoid SomeMethodThatUsesTheFile()\n\t{\n\t\tvar pathToFile = myFile.FullPath;\n\t\t...\n\t}\n\n\tpublic void Dispose()\n\t{\n\t\t// Clean up the file\n\t\tmyFile?.Dispose();\n\t}\n}\n```\n\nMaterializing a directory structure\n\n```csharp\npublic class DirectoryLoadingClass: AutoResourceLoader, IDisposable\n{\n\t[EmbeddedResource('Resources')]\t\t// Get all embedded resources below this project folder.\n\tprivate TempDirectory myDir { get; set; }\n\n\tvoid SomeMethodThatUsesTheFiles()\n\t{\n\t\tvar pathToFiles = myDir.FullPath;\n\t\t...\n\t}\n\n\tpublic void Dispose()\n\t{\n\t\t// Delete the directory structure\n\t\tmyDir?.Dispose();\n\t}\n}\n```\n\n# Examples in Other Repositories\n\nYou can see this library in action in the unit test projects in my other repositories\n\n* [Firefly.CloudFormation](https://github.com/fireflycons/Firefly.CloudFormation/tree/master/tests/Firefly.CloudFormation.Tests.Unit)\n* [PSCloudFomation](https://github.com/fireflycons/PSCloudFormation/tree/master/tests/Firefly.PSCloudFormation.Tests.Unit)\n\n\n# API Documentation and Further Examples\n\nThis can be found on the [documentation site](https://fireflycons.github.io/Firefly-EmbeddedResourceLoader)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffireflycons%2Ffirefly.embeddedresourceloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffireflycons%2Ffirefly.embeddedresourceloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffireflycons%2Ffirefly.embeddedresourceloader/lists"}