// // NullableWrapper.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Diagnostics.CodeAnalysis; namespace NosSmooth.PacketSerializer.Abstractions; /// /// Wraps a compound value that may not be present /// and there will be "-1" instead in the packet. /// The converter of underlying type will be called /// if and only if the value is not null. /// /// The value. /// The underlying type. [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1313:Parameter names should begin with lower-case letter", Justification = "Fix this, this should not happen.")] public record struct NullableWrapper(T? Value) { /// /// Unwrap the underlying value. /// /// The wrapper to unwrap. /// The unwrapped value. public static implicit operator T?(NullableWrapper wrapper) { return wrapper.Value; } public static implicit operator NullableWrapper(T? value) { return new NullableWrapper(value); } }