internal bool TryGetValue(TKey key, out TValue value) { // First try to get the cached value for this compilation. lock (_valueMap) { if (_valueMap.TryGetValue(key, out value)) { return true; } } // Ask the core analysis value provider for the value. // We do it outside the lock statement as this may call into user code which can be a long running operation. if (!_analysisValueProvider.TryGetValue(key, out value)) { value = default(TValue); return false; } // Store the value for the lifetime of the compilation. lock (_valueMap) { _valueMap[key] = value; } return true; }
internal bool TryGetValue(TKey key, out TValue value) { // First try to get the cached value for this compilation. lock (_valueMap) { if (_valueMap.TryGetValue(key, out value)) { return(true); } } // Ask the core analysis value provider for the value. // We do it outside the lock statement as this may call into user code which can be a long running operation. if (!_analysisValueProvider.TryGetValue(key, out value)) { value = default(TValue); return(false); } // Store the value for the lifetime of the compilation. lock (_valueMap) { // Check if another thread already stored the computed value. TValue storedValue; if (_valueMap.TryGetValue(key, out storedValue)) { // If so, we return the stored value. value = storedValue; } else { // Otherwise, store the value computed here. _valueMap.Add(key, value); } } return(true); }