/
Result.VolumeResult.cs
74 lines (64 loc) · 2.43 KB
/
Result.VolumeResult.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (c) Dmytro Kyshchenko. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics.CodeAnalysis;
namespace xFunc.Maths.Results;
public abstract partial class Result
{
/// <summary>
/// Converts <see cref="VolumeValue"/> to <see cref="VolumeResult"/>.
/// </summary>
/// <param name="volume">The volume value.</param>
/// <returns>The volume result.</returns>
[ExcludeFromCodeCoverage]
public static implicit operator Result(VolumeValue volume)
=> new VolumeResult(volume);
/// <summary>
/// Gets the volume value.
/// </summary>
/// <param name="volumeValue">The volume value.</param>
/// <returns><c>true</c> if the current instance contains <see cref="VolumeValue"/>, otherwise <c>false</c>.</returns>
public bool TryGetVolume([NotNullWhen(true)] out VolumeValue? volumeValue)
{
if (this is VolumeResult volumeResult)
{
volumeValue = volumeResult.Volume;
return true;
}
volumeValue = null;
return false;
}
/// <summary>
/// Gets the volume value.
/// </summary>
/// <exception cref="InvalidCastException">Thrown when the current instance is not <see cref="VolumeResult"/>.</exception>
[ExcludeFromCodeCoverage]
public virtual VolumeValue Volume
=> ((VolumeResult)this).Volume;
/// <summary>
/// Represents the volume result.
/// </summary>
public sealed class VolumeResult : Result
{
/// <summary>
/// Initializes a new instance of the <see cref="Result.VolumeResult"/> class.
/// </summary>
/// <param name="volume">The volume value.</param>
public VolumeResult(VolumeValue volume)
=> Volume = volume;
/// <summary>
/// Converts <see cref="Result.VolumeResult"/> to <see cref="VolumeValue"/>.
/// </summary>
/// <param name="volumeResult">The volume result.</param>
/// <returns>The volume value.</returns>
[ExcludeFromCodeCoverage]
public static implicit operator VolumeValue(VolumeResult volumeResult)
=> volumeResult.Volume;
/// <inheritdoc />
public override string ToString()
=> Volume.ToString();
/// <summary>
/// Gets the volume value.
/// </summary>
public override VolumeValue Volume { get; }
}
}