// Token: 0x060017B2 RID: 6066 RVA: 0x00073A8C File Offset: 0x00071C8C internal static void RevertRequest(StaticResourceExtension requester, bool success) { ResourceDictionaryDiagnostics.LookupResult lookupResult = ResourceDictionaryDiagnostics._lookupResultStack.Pop(); if (!success) { return; } if (lookupResult.Requester.GetType() == typeof(StaticResourceExtension)) { return; } if (ResourceDictionaryDiagnostics._resultCache == null) { ResourceDictionaryDiagnostics._resultCache = new Dictionary <WeakReferenceKey <StaticResourceExtension>, WeakReference <ResourceDictionary> >(); } WeakReferenceKey <StaticResourceExtension> key = new WeakReferenceKey <StaticResourceExtension>(requester); ResourceDictionary dictionary = null; WeakReference <ResourceDictionary> weakReference; bool flag = ResourceDictionaryDiagnostics._resultCache.TryGetValue(key, out weakReference); if (flag) { weakReference.TryGetTarget(out dictionary); } if (lookupResult.Dictionary != null) { ResourceDictionaryDiagnostics._resultCache[key] = new WeakReference <ResourceDictionary>(lookupResult.Dictionary); return; } lookupResult.Key = requester.ResourceKey; lookupResult.Dictionary = dictionary; }
internal static void RevertRequest(StaticResourceExtension requester, bool success) { LookupResult result = _lookupResultStack.Pop(); Debug.Assert(Object.Equals(result.Requester, requester), "Reverting a request for the wrong requester"); // if the request failed, nothing more to do if (!success) { return; } // simple case - no deferred content, no lookup optimizations if (result.Requester.GetType() == typeof(StaticResourceExtension)) { Debug.Assert(result.Dictionary != null, "simple lookup resolved incorrectly"); return; } // complex case (see (1) in remarks in RecordLookupResultImpl above) // Maintain a cache mapping requester to the dictionary it used. // Use weak references to avoid memory leaks. if (_resultCache == null) { _resultCache = new Dictionary <WeakReferenceKey <StaticResourceExtension>, WeakReference <ResourceDictionary> >(); } WeakReferenceKey <StaticResourceExtension> wrKey = new WeakReferenceKey <StaticResourceExtension>(requester); WeakReference <ResourceDictionary> wrDict; ResourceDictionary cachedDict = null; bool found = _resultCache.TryGetValue(wrKey, out wrDict); if (found) { wrDict.TryGetTarget(out cachedDict); } if (result.Dictionary != null) { // The first time the class requests a value, cache the dictionary if (cachedDict != null) { Debug.Assert(cachedDict == result.Dictionary, "conflicting dictionaries for a StaticResource reference"); } _resultCache[wrKey] = new WeakReference <ResourceDictionary>(result.Dictionary); } else { // for subsequent (optimized) requests, use the dictionary from the cache Debug.Assert(cachedDict != null, "no dictionary found for StaticResource reference"); result.Key = requester.ResourceKey; result.Dictionary = cachedDict; } }
private List<KeyValuePair<int, object>> EnsureItemValues(object item) { WeakReferenceKey<object> key; Dictionary<WeakReferenceKey<object>, List<KeyValuePair<int, object>>> itemValueStorage = EnsureItemValueStorage(); List<KeyValuePair<int, object>> itemValues = GetItemValues(item, itemValueStorage); if (itemValues == null && HashHelper.HasReliableHashCode(item)) { key = new WeakReferenceKey<object>(item); itemValues = new List<KeyValuePair<int, object>>(3); // So far the only use of this is to store three values. itemValueStorage[key] = itemValues; } return itemValues; }
private List<KeyValuePair<int, object>> GetItemValues(object item, Dictionary<WeakReferenceKey<object>, List<KeyValuePair<int, object>>> itemValueStorage) { Debug.Assert(item != null); List<KeyValuePair<int, object>> itemValues = null; WeakReferenceKey<object> key; if (itemValueStorage != null) { key = new WeakReferenceKey<object>(item); itemValueStorage.TryGetValue(key, out itemValues); } return itemValues; }