/// <summary> /// This should never be called with null declaringType, updateArgumentParameters or generator references and updateArgumentParameters should /// not be empty nor contain any null references. The declaringType should have a paramterType that is assignable to typeparam T. /// </summary> public void Set <T>(Type declaringType, IEnumerable <ParameterInfo> updateArgumentParameters, UpdateWithSignature <T> generator) { if (generator == null) { throw new ArgumentException("generator"); } // This will throw argument exceptions for declaringType and updateArgumentParameters if required var cacheKey = new CacheKeyData(typeof(T), declaringType, updateArgumentParameters); // Add the item if it doesn't already exist and overwrite it if it does _cache.AddOrUpdate(cacheKey, generator, (existingCacheKey, existingValue) => generator); }
/// <summary> /// This should never be called with null declaringType or updateArgumentParameters references and updateArgumentParameters should not be empty /// nor contain any null references. The declaringType should have a paramterType that is assignable to typeparam T. This should return null /// if the cache can not provide the requested data. /// </summary> public UpdateWithSignature <T> GetIfAvailable <T>(Type declaringType, IEnumerable <ParameterInfo> updateArgumentParameters) { // This will throw argument exceptions for declaringType and updateArgumentParameters if required var cacheKey = new CacheKeyData(typeof(T), declaringType, updateArgumentParameters); // If the item is available as the correct type, return it - otherwise return null (if not available or if not the required type) object cachedResult; if (_cache.TryGetValue(cacheKey, out cachedResult)) { return(cachedResult as UpdateWithSignature <T>); } return(null); }