-
Notifications
You must be signed in to change notification settings - Fork 0
/
ROP.cs
51 lines (42 loc) · 1.45 KB
/
ROP.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
using System.ComponentModel;
using JetBrains.Annotations;
// "ROP": Railway Oriented Programming. For more info see:
// https://fsharpforfunandprofit.com/rop/
// https://fsharpforfunandprofit.com/posts/recipe-part2/
namespace NTRightsNet
{
//--------------------------------------------------
/// <summary>
/// Simple railway-oriented programming general result.
/// </summary>
// ReSharper disable once UnusedTypeParameter - type is used to document what type is being returned (when successful)
internal abstract class Result<T> {}
//--------------------------------------------------
/// <summary>
/// Simple railway-oriented programming failure result.
/// </summary>
/// <inheritdoc />
internal sealed class Failure<T> : Result<T>
{
public Failure([NotNull] string message, int win32Error = 0)
{
this.Message = (win32Error == 0
? message
: $"{message} (0x{win32Error:X8}: {new Win32Exception(win32Error).Message})");
}
[NotNull] public string Message { get; }
}
//--------------------------------------------------
/// <summary>
/// Simple railway-oriented programming successful result.
/// </summary>
/// <inheritdoc />
internal sealed class Success<T> : Result<T>
{
public Success([NotNull] T value)
{
this.Value = value;
}
[NotNull] public T Value { get; }
}
}