2021-05-30 16:56:56 -04:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
|
|
2021-05-30 16:48:43 -04:00
|
|
|
namespace EpicGames.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Explicitly boxes a value type, allowing it to be passed by reference to (and modified in) an async method.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
2021-05-30 16:56:32 -04:00
|
|
|
public class Boxed<T>
|
2021-05-30 16:48:43 -04:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The struct value
|
|
|
|
|
/// </summary>
|
|
|
|
|
public T Value { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Default constructor
|
|
|
|
|
/// </summary>
|
2022-03-24 16:35:00 -04:00
|
|
|
/// <param name="value">The value to copy</param>
|
|
|
|
|
public Boxed(T value)
|
2021-05-30 16:48:43 -04:00
|
|
|
{
|
2022-03-24 16:35:00 -04:00
|
|
|
Value = value;
|
2021-05-30 16:48:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public override string? ToString()
|
|
|
|
|
{
|
2021-05-30 16:56:32 -04:00
|
|
|
return Value?.ToString();
|
2021-05-30 16:48:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implicit conversion of a boxed value to value type
|
|
|
|
|
/// </summary>
|
2022-03-24 16:35:00 -04:00
|
|
|
/// <param name="boxed"></param>
|
|
|
|
|
public static implicit operator T(Boxed<T> boxed)
|
2021-05-30 16:48:43 -04:00
|
|
|
{
|
2022-03-24 16:35:00 -04:00
|
|
|
return boxed.Value;
|
2021-05-30 16:48:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Implicit conversion of a boxed value to value type
|
|
|
|
|
/// </summary>
|
2022-03-24 16:35:00 -04:00
|
|
|
/// <param name="value"></param>
|
|
|
|
|
public static implicit operator Boxed<T>(T value)
|
2021-05-30 16:48:43 -04:00
|
|
|
{
|
2022-03-24 16:35:00 -04:00
|
|
|
return new Boxed<T>(value);
|
2021-05-30 16:48:43 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|