-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuidPatterns.fs
More file actions
230 lines (208 loc) · 10.3 KB
/
Copy pathGuidPatterns.fs
File metadata and controls
230 lines (208 loc) · 10.3 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
namespace XNetEx.FSharp.Core
open System
open XNetEx.FSharp.Core
/// <summary>
/// Contains active patterns for matching values of type <see cref="T:System.Guid"/>.
/// </summary>
[<AutoOpen>]
module GuidPatterns =
/// <summary>
/// Matches fields of <see cref="T:System.Guid"/> values.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>The fields of the <see cref="T:System.Guid"/>.</returns>
[<CompiledName("GuidFieldsPattern")>]
let (|GuidFields|) (guid: Guid)
: struct (int * int16 * int16 * struct (byte * byte) *
struct (byte * byte * byte * byte * byte * byte)) =
Guid.toFields guid
/// <summary>
/// Matches variants of <see cref="T:System.Guid"/> values.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>The variant of the <see cref="T:System.Guid"/>.</returns>
[<CompiledName("GuidVariantPattern")>]
let (|GuidVariant|) (guid: Guid) : Guid.Variant =
Guid.variant guid
/// <summary>
/// Matches versions of <see cref="T:System.Guid"/> values.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>The version of the <see cref="T:System.Guid"/>.</returns>
[<CompiledName("GuidVersionPattern")>]
let (|GuidVersion|) (guid: Guid) : Guid.Version =
Guid.version guid
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that is time-based.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the timestamp.</returns>
[<CompiledName("TimeBasedGuidPattern"); return: Struct>]
let (|TimeBasedGuid|_|) (guid: Guid) : DateTime voption =
Guid.tryGetTime guid
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that is name-based.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the hash data and its bitmask.</returns>
[<CompiledName("NameBasedGuidPattern"); return: Struct>]
let (|NameBasedGuid|_|) (guid: Guid) : Guid.DataAndMask voption =
Guid.tryGetHashData guid
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that is generated randomly.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the random data and its bitmask.</returns>
[<CompiledName("RandomizedGuidPattern"); return: Struct>]
let (|RandomizedGuid|_|) (guid: Guid) : Guid.DataAndMask voption =
Guid.tryGetRandomData guid
#if !UUIDREV_DISABLE
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that contains custom data.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the custom data and its bitmask.</returns>
[<CompiledName("CustomizedGuidPattern"); return: Struct>]
let (|CustomizedGuid|_|) (guid: Guid) : Guid.DataAndMask voption =
Guid.tryGetCustomData guid
#endif
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that contains a clock sequence.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the clock sequence.</returns>
[<CompiledName("GuidClockSequencePattern"); return: Struct>]
let (|GuidClockSeq|_|) (guid: Guid) : int16 voption =
Guid.tryGetClockSeq guid
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that contains local ID data.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the DCE Security domain and local ID.</returns>
[<CompiledName("GuidDomainAndLocalIdPattern"); return: Struct>]
let (|GuidLocalId|_|) (guid: Guid) : struct (Guid.Domain * int) voption =
Guid.tryGetLocalId guid
/// <summary>
/// Matches <see cref="T:System.Guid"/> values that contains node ID data.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the node ID.</returns>
[<CompiledName("GuidNodeIdPattern"); return: Struct>]
let (|GuidNodeId|_|) (guid: Guid) : byte[] voption =
Guid.tryGetNodeId guid
/// <summary>
/// Matches <see cref="T:System.Guid"/> values whose value is all zeros.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A unit value option.</returns>
[<CompiledName("GuidEmptyPattern"); return: Struct>]
let (|GuidEmpty|_|) (guid: Guid) : unit voption =
Guid.(=)(guid, Guid.empty) |> ValueOption.ofBool
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 4122 UUID version 1.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the timestamp, clock sequence and node ID.</returns>
[<CompiledName("GuidVersion1Pattern"); return: Struct>]
let (|GuidVersion1|_|) (guid: Guid) : struct (DateTime * int16 * byte[]) voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version1 -> ValueSome struct (
Guid.tryGetTime guid |> ValueOption.get,
Guid.tryGetClockSeq guid |> ValueOption.get,
Guid.tryGetNodeId guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 4122 UUID version 2.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the timestamp, clock sequence,
/// DCE Security domain and local ID and node ID.</returns>
[<CompiledName("GuidVersion2Pattern"); return: Struct>]
let (|GuidVersion2|_|) (guid: Guid)
: struct (DateTime * int16 * struct (Guid.Domain * int) * byte[]) voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version2 -> ValueSome struct (
Guid.tryGetTime guid |> ValueOption.get,
Guid.tryGetClockSeq guid |> ValueOption.get,
Guid.tryGetLocalId guid |> ValueOption.get,
Guid.tryGetNodeId guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 4122 UUID version 3.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the hash data and its bitmask.</returns>
[<CompiledName("GuidVersion3Pattern"); return: Struct>]
let (|GuidVersion3|_|) (guid: Guid) : Guid.DataAndMask voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version3 -> ValueSome (
Guid.tryGetHashData guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 4122 UUID version 4.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the random data and its bitmask.</returns>
[<CompiledName("GuidVersion4Pattern"); return: Struct>]
let (|GuidVersion4|_|) (guid: Guid) : Guid.DataAndMask voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version4 -> ValueSome (
Guid.tryGetRandomData guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 4122 UUID version 5.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the hash data and its bitmask.</returns>
[<CompiledName("GuidVersion5Pattern"); return: Struct>]
let (|GuidVersion5|_|) (guid: Guid) : Guid.DataAndMask voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version5 -> ValueSome (
Guid.tryGetHashData guid |> ValueOption.get)
| _, _ -> ValueNone
#if !UUIDREV_DISABLE
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 9562 UUID version 6.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the timestamp, clock sequence and node ID.</returns>
[<CompiledName("GuidVersion6Pattern"); return: Struct>]
let (|GuidVersion6|_|) (guid: Guid) : struct (DateTime * int16 * byte[]) voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version6 -> ValueSome struct (
Guid.tryGetTime guid |> ValueOption.get,
Guid.tryGetClockSeq guid |> ValueOption.get,
Guid.tryGetNodeId guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 9562 UUID version 7.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the timestamp and random data and its bitmask.</returns>
[<CompiledName("GuidVersion7Pattern"); return: Struct>]
let (|GuidVersion7|_|) (guid: Guid) : struct (DateTime * Guid.DataAndMask) voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version7 -> ValueSome struct (
Guid.tryGetTime guid |> ValueOption.get,
Guid.tryGetRandomData guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values of RFC 9562 UUID version 8.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A value option of the custom data and its bitmask.</returns>
[<CompiledName("GuidVersion8Pattern"); return: Struct>]
let (|GuidVersion8|_|) (guid: Guid) : Guid.DataAndMask voption =
match Guid.isRfc4122 guid, Guid.version guid with
| true, Guid.Version.Version8 -> ValueSome (
Guid.tryGetCustomData guid |> ValueOption.get)
| _, _ -> ValueNone
/// <summary>
/// Matches <see cref="T:System.Guid"/> values whose value is all ones.
/// </summary>
/// <param name="guid">The <see cref="T:System.Guid"/>.</param>
/// <returns>A unit value option.</returns>
[<CompiledName("GuidMaxValuePattern"); return: Struct>]
let (|GuidMaxValue|_|) (guid: Guid) : unit voption =
Guid.(=)(guid, Guid.maxValue) |> ValueOption.ofBool
#endif