// bool TryGetValue(TKey key, out TValue value) internal bool TryGetValue <K, V>(K key, out V value) { if (key == null) { throw new ArgumentNullException(nameof(key)); } IMapView <K, V> _this = JitHelpers.UnsafeCast <IMapView <K, V> >(this); // It may be faster to call HasKey then Lookup. On failure, we would otherwise // throw an exception from Lookup. if (!_this.HasKey(key)) { value = default(V); return(false); } try { value = _this.Lookup(key); return(true); } catch (Exception ex) // Still may hit this case due to a race condition { if (__HResults.E_BOUNDS == ex._HResult) { value = default(V); return(false); } throw; } }
internal bool TryGetValue <K, V>(K key, out V value) { if (key == null) { throw new ArgumentNullException("key"); } IMapView <K, V> mapView = JitHelpers.UnsafeCast <IMapView <K, V> >(this); if (!mapView.HasKey(key)) { value = default(V); return(false); } bool result; try { value = mapView.Lookup(key); result = true; } catch (Exception ex) { if (-2147483637 != ex._HResult) { throw; } value = default(V); result = false; } return(result); }
private static V Lookup <K, V>(IMapView <K, V> _this, K key) { try { return(_this.Lookup(key)); } catch (Exception ex) { if (-2147483637 == ex._HResult) { throw new KeyNotFoundException(Environment.GetResourceString("Arg_KeyNotFound")); } throw; } }
private static V Lookup <K, V>(IMapView <K, V> _this, K key) { Contract.Requires(null != key); try { return(_this.Lookup(key)); } catch (Exception ex) { if (__HResults.E_BOUNDS == ex._HResult) { throw new KeyNotFoundException(Environment.GetResourceString("Arg_KeyNotFound")); } throw; } }
private static V Lookup <K, V>(IMapView <K, V> _this, K key) { Debug.Assert(null != key); try { return(_this.Lookup(key)); } catch (Exception ex) { if (HResults.E_BOUNDS == ex.HResult) { throw new KeyNotFoundException(SR.Format(SR.Arg_KeyNotFoundWithKey, key.ToString())); } throw; } }
private static V Lookup <K, V>(IMapView <K, V> _this, K key) { Contract.Requires(null != key); try { return(_this.Lookup(key)); } catch (Exception ex) { if (HResults.E_BOUNDS == ex._HResult) { throw new KeyNotFoundException(SR.Arg_KeyNotFound); } throw; } }