{"id":16482189,"url":"https://github.com/cajuncoding/assemblyattributesearch","last_synced_at":"2025-02-28T18:19:46.391Z","repository":{"id":116950392,"uuid":"252275468","full_name":"cajuncoding/AssemblyAttributeSearch","owner":"cajuncoding","description":"This is a small library/helper to provide greatly simplified convenience methods for dynamically finding, filtering,  and initializing classes based on Custom Attributes.","archived":false,"fork":false,"pushed_at":"2021-01-04T02:02:42.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2024-04-29T01:42:54.910Z","etag":null,"topics":["assembly","attribute-based","attributes","csharp","csharp-code","csharp-library","reflection"],"latest_commit_sha":null,"homepage":"https://github.com/cajuncoding/AssemblyAttributeSearch","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/cajuncoding.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-04-01T20:06:08.000Z","updated_at":"2022-01-17T05:55:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"41d72e1e-fc9c-470f-be5b-cfc30ecf024a","html_url":"https://github.com/cajuncoding/AssemblyAttributeSearch","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cajuncoding%2FAssemblyAttributeSearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cajuncoding%2FAssemblyAttributeSearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cajuncoding%2FAssemblyAttributeSearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cajuncoding%2FAssemblyAttributeSearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cajuncoding","download_url":"https://codeload.github.com/cajuncoding/AssemblyAttributeSearch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241198975,"owners_count":19926554,"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":["assembly","attribute-based","attributes","csharp","csharp-code","csharp-library","reflection"],"created_at":"2024-10-11T13:09:55.993Z","updated_at":"2025-02-28T18:19:46.366Z","avatar_url":"https://github.com/cajuncoding.png","language":"C#","readme":"# AssemblyAttributeSearch\nThis is a small small .Net Standard library/helper to provide greatly simplified convenience methods for dynamically finding, filtering, \nand initializing classes based on Custom Attributes. It provides a simpel convenience methods to allow searching \nfor all instances of a Custom Attribute type. \n\nIn addition, you may specify an optional Class/Interface filter to only return types that implement the given class/interface.\n\nThe results will have the details of the Attribute found, as well as the class type for the calling code to use (e.g. process, instantiate dynamically, etc.).1\n\nThe default behavior assumes that there may be instances where Interfaces, and classes are defined in separate class Librareis and may\nin which the Assembly may not yet be loaded. In which case the local assemblies -- in the same root/bin folder as the specified assembly --\nare eagerly loaded (e.g. force loaded) so that all libraries are available to be searched.\n\nThis was important for my use case whereby I wanted to have a generic Factory that could create instances of any class that implmented\nmy interface and had appropriate metadata defined by my Custom Attribute.  This allowed develoeprs to create many implementations easily\nwithout any impact to the core framework that could instantiate and implement the use of those classes.\n\nNOTE: In the context of Azure Functions, the Assembly.GetExecutingAssembly() method results in a dynamic `func` and not the original\nproject assembly, therefore the local class libraries could not be found and loaded as expected.  The solution is to simply use \nthe Assembly property of a specific type (e.g. this.GetType().Assembly) that exists in the main project assembly and everythign \nwill resolve as expected; as noted in the samples below.\n\n## Nuget Package\nTo use behaviors in your project, add the [AssemblyAttributeSearch NuGet package](https://www.nuget.org/packages/AssemblyAttributeSearch/) to your project.\n\n## Project Goals \u0026 Benefits (Why did I share this?)\n* Provide a very simple and lightweight library for searching/filtering all assemblies for Classes and their associated Attributes.\n* Implement internal static caching for performance so that reflection calls do not need to be made for the same searches more than once.\n* Return all related data for both the Attribute \u0026 Class Types in the response so that no additional Reflection processing is needed.\n** I originally used `FluentAssemblyScanner` (a great looking project) however did not want to have to scan assemblies and then do additional lookups to get my Attribute data again.\n** In addition, much of the `FluentAssemblyScanner` library was unused so something even lighter weight could meet my needs (and many others I believe).\n\n## Usage\nTo get all classes \u0026 attribute info. for all classes denoted with a given `JediAttribute` Custom Attribute:\n```\nvar thisAssembly = this.GetType().Assembly;\n\n//This gets the list of all search results...\nvar allJediClassInfoList = AssemblyAttributeSearch\u003cJediAttribute\u003e.FindAllAttributedClasses(thisAssembly);\n\n//This convenience method lets us instanticate an instance (via Relfection)\nvar dynamicallyCreatedJedi = allJediClassInfoList.FirstOrDefault()?.CreateInstanc\u003cIJedi\u003e();\n```\n\nTo get only the classes \u0026 attribute info. with a given `JediAttribute` and that also implements the IJediMaster Interface:\n```\nvar thisAssembly = this.GetType().Assembly;\n\n//This gets the list of all search results...\nvar jediMasterClassInfoList = AssemblyAttributeSearch\u003cJediAttribute\u003e.FindAllAttributedClasses(thisAssembly, typeof(IJediMaster));\n\n//This convenience method lets us instanticate an instance (via Relfection)\nvar dynamicallyCreatedJediMaster = jediMasterClassInfoList.FirstOrDefault()?.CreateInstanc\u003cIJediMaster\u003e();\n```\n\nOr if you just want to force load the local class libraries via the Helper and then process with your own Reflection Logic:\n```\n//Eagerly load all local assemblies...\nAssemblyLoadHelper.ForceLoadClassLibraries(this.GetType().Assembly);\n\n//Now you can retrieve and process all types in all assemblies even if they have not yet been lazy initialized by .Net Framework...\nvar allTypesInAllLocalAssemblies = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a =\u003e a.GetTypes());\n```\n\n```\n/*\nMIT License\n\nCopyright (c) 2018\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n*/\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcajuncoding%2Fassemblyattributesearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcajuncoding%2Fassemblyattributesearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcajuncoding%2Fassemblyattributesearch/lists"}