The fastest .NET Reflection cache
https://soenneker.com โ HEALTH ? 99 / Healthy
// readme
Soenneker.Reflection.Cache
Caches reflection metadata, lookups, constructed generics, custom attributes, and compiled member accessors for repeated use.
Installation
dotnet add package Soenneker.Reflection.Cache
Registration
using Soenneker.Reflection.Cache.Registrars;
services.AddReflectionCacheAsSingleton();
A singleton gives the application one shared metadata graph and the highest cache reuse. Use AddReflectionCacheAsScoped() when metadata must stop being retained with a scope. The cache has no eviction API; its cached Type, member, attribute, and delegate references live as long as the cache does. Avoid a long-lived cache for types loaded into collectible AssemblyLoadContext instances.
For manual construction:
var cache = new ReflectionCache();
Thread safety is enabled by default. new ReflectionCache(threadSafe: false) removes concurrency protection and is suitable only when the cache instance is confined to one thread.
Follow the cached chain
CachedType cachedType = cache.GetCachedType(typeof(OrderHandler));
CachedMethod? method = cachedType.GetCachedMethod(
nameof(OrderHandler.Handle),โฆ