A small value type representing a command duration, either a positive finite TimeSpan or an explicit permanent value. Used by the SboxSuperuser command API so callers can distinguish 'permanent' from a zero or unset duration.
namespace SboxSuperuser;
/// <summary>An explicit positive duration or permanent value, without parsing or expiry scheduling.</summary>
public sealed class CommandDuration
{
/// <summary>Gets the finite duration, or null for an explicit permanent value.</summary>
public TimeSpan? Value { get; }
/// <summary>Gets whether the caller explicitly selected permanent duration.</summary>
public bool IsPermanent => !Value.HasValue;
/// <summary>Gets the explicit permanent value; zero is never used as a synonym.</summary>
public static CommandDuration Permanent { get; } = new CommandDuration();
private CommandDuration()
{
}
/// <summary>Creates a positive finite duration.</summary>
public CommandDuration( TimeSpan value )
{
if ( value <= TimeSpan.Zero )
{
throw new ArgumentOutOfRangeException( nameof( value ), "Duration must be positive." );
}
Value = value;
}
}