|
1 | 1 | // Copyright Subatomix Research Inc. |
2 | 2 | // SPDX-License-Identifier: MIT |
3 | 3 |
|
4 | | -// TODO: Document |
5 | | -#pragma warning disable CS1591 |
6 | | - |
7 | 4 | namespace PSql; |
8 | 5 |
|
| 6 | +/// <summary> |
| 7 | +/// Validates that a parameter is either <see langword="null"/> or a valid |
| 8 | +/// timeout value. |
| 9 | +/// </summary> |
| 10 | +/// <remarks> |
| 11 | +/// Valid timeouts range from <c>00:00:00</c> to <c>24855.03:14:07</c>. |
| 12 | +/// </remarks> |
9 | 13 | public class ValidateNullOrTimeoutAttribute : ValidateArgumentsAttribute |
10 | 14 | { |
11 | 15 | private const long |
12 | | - MinValueTicks = 0L, |
13 | | - MaxValueTicks = 2147483647_0000000L; |
| 16 | + MinValueTicks = 0 * TimeSpan.TicksPerSecond, // 00:00:00 |
| 17 | + MaxValueTicks = int.MaxValue * TimeSpan.TicksPerSecond; // 24855.03:14:07 |
14 | 18 |
|
15 | | - protected override void Validate(object arg, EngineIntrinsics engine) |
| 19 | + /// <inheritdoc/> |
| 20 | + protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) |
16 | 21 | { |
17 | | - if (arg is null) |
| 22 | + // NOTE: 'arguments' is a single argument, despite the plural name. |
| 23 | + |
| 24 | + if (arguments is null) |
18 | 25 | return; |
19 | 26 |
|
20 | | - if (arg is PSObject psObject) |
21 | | - arg = psObject.BaseObject; |
| 27 | + if (arguments is PSObject psObject) |
| 28 | + arguments = psObject.BaseObject; |
22 | 29 |
|
23 | | - var value = LanguagePrimitives.ConvertTo<TimeSpan>(arg); |
| 30 | + var value = LanguagePrimitives.ConvertTo<TimeSpan>(arguments); |
24 | 31 | var ticks = value.Ticks; |
25 | 32 |
|
26 | 33 | if (ticks < MinValueTicks) |
27 | 34 | throw new ValidationMetadataException(string.Format( |
28 | | - @"The value ""{0}"" is negative. Negative timeouts are not supported.", arg |
| 35 | + @"The value ""{0}"" is negative. Negative timeouts are not supported.", arguments |
29 | 36 | )); |
30 | 37 |
|
31 | 38 | if (ticks > MaxValueTicks) |
32 | 39 | throw new ValidationMetadataException(string.Format( |
33 | | - @"The value ""{0}"" exceeds the maximum supported timeout, 24855.03:14:07.", arg |
| 40 | + @"The value ""{0}"" exceeds the maximum supported timeout, 24855.03:14:07.", arguments |
34 | 41 | )); |
35 | 42 | } |
36 | 43 | } |
0 commit comments