public bool Equals(WeakReferenceCompareValue <TK> other) { if (other is null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (_hashCode != other._hashCode) { return(false); } if (_weak.TryGetTarget(out var x) == false || other._weak.TryGetTarget(out var y) == false) { return(false); } return(ReferenceEquals(x, y)); }
/// <summary> /// Initializes the <see cref="DisposableThreadLocal{T}"/> instance with the /// specified <paramref name="valueFactory"/> function. /// </summary> /// <param name="valueFactory">The <see cref="Func{T, TResult}"/> invoked to produce a /// lazily-initialized value when an attempt is made to retrieve <see cref="Value"/> /// without it having been previously initialized.</param> /// <exception cref="ArgumentNullException"><paramref name="valueFactory"/> is <c>null</c>.</exception> public DisposableThreadLocal(Func <T> valueFactory) { _valueFactory = valueFactory ?? throw new ArgumentNullException(nameof(valueFactory)); selfReference = new WeakReferenceCompareValue <DisposableThreadLocal <T> >(this); }
/// <summary> /// Initializes the <see cref="DisposableThreadLocal{T}"/> instance. /// </summary> /// <remarks> /// The default value of <typeparamref name="T"/> is used to initialize /// the instance when <see cref="Value"/> is accessed for the first time. /// </remarks> public DisposableThreadLocal() { selfReference = new WeakReferenceCompareValue <DisposableThreadLocal <T> >(this); }
public CurrentThreadState() { selfReference = new WeakReferenceCompareValue <CurrentThreadState>(this); }
public LightWeightThreadLocal(Func <T> generator = null) { _generator = generator; SelfReference = new WeakReferenceCompareValue <LightWeightThreadLocal <T> >(this); }