bool IObfuscationContext.TryGetSurrogateValue(IDictionarySpec dictionarySpec, object surrogateKey, out object surrogateValue) { IDictionary <object, object> dictionaryCache; if ((object)dictionarySpec == null) { throw new ArgumentNullException(nameof(dictionarySpec)); } if (!this.ObfuscationSpec.DisableEngineCaches ?? false) { if (!this.SubstitutionCacheRoot.TryGetValue(dictionarySpec.DictionaryId, out dictionaryCache)) { dictionaryCache = new Dictionary <object, object>(); this.SubstitutionCacheRoot.Add(dictionarySpec.DictionaryId, dictionaryCache); } if (!dictionaryCache.TryGetValue(surrogateKey, out surrogateValue)) { if (dictionarySpec.PreloadEnabled) { throw new InvalidOperationException(string.Format("Cache miss when dictionary preload enabled for dictionary ID '{0}'; current cache slot item count: {1}.", dictionarySpec.DictionaryId, dictionaryCache.Count)); } surrogateValue = this.ResolveDictionaryValue(dictionarySpec, surrogateKey); dictionaryCache.Add(surrogateKey, surrogateValue); } } else { surrogateValue = this.ResolveDictionaryValue(dictionarySpec, surrogateKey); } return(true); }
private object ResolveDictionaryValue(IDictionarySpec dictionarySpec, object surrogateKey) { if ((object)dictionarySpec == null) { throw new ArgumentNullException(nameof(dictionarySpec)); } if ((object)surrogateKey == null) { throw new ArgumentNullException(nameof(surrogateKey)); } if ((object)this.ResolveDictionaryValueCallback == null) { return(null); } return(this.ResolveDictionaryValueCallback(dictionarySpec, surrogateKey)); }