// MIT License - Copyright (c) 2023 wallstop // Full license text: https://github.com/wallstop/unity-helpers/blob/main/LICENSE namespace WallstopStudios.UnityHelpers.Core.Helper { /// /// Provides utility methods for atomic value exchange operations. /// /// /// Thread Safety: Methods are not inherently thread-safe. For thread-safe exchanges, use Interlocked.Exchange. /// Performance: O(1) operations with minimal overhead. /// public static class AssignUtilities { /// /// Atomically exchanges a variable's value and returns the old value. /// /// The type of the values being exchanged. /// Reference to the variable to assign to. /// The new value to assign. /// The old value of assignTo before the exchange. /// /// Null handling: Works with null values for reference types. /// Thread-safe: No. Use Interlocked.Exchange for thread-safe operations. /// Performance: O(1) - single assignment and return. /// Allocations: None. /// Edge cases: For reference types, both old and new values can be null. /// public static T Exchange(ref T assignTo, T assignFrom) { T oldValue = assignTo; assignTo = assignFrom; return oldValue; } } }