using JetBrains.Annotations; using System.Threading; namespace ASCOM.Meade.net { public class ThreadSafeValue { private object _value; public ThreadSafeValue(in T value) => _value = value; public void Set(in T value) => Interlocked.Exchange(ref _value, value); public static implicit operator ThreadSafeValue(in T value) => new ThreadSafeValue(value); public static implicit operator T([NotNull] ThreadSafeValue @this) => (T)(@this?._value ?? default); } }