-
Notifications
You must be signed in to change notification settings - Fork 8
/
HelperMethods.cs
37 lines (31 loc) · 1.08 KB
/
HelperMethods.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
using System;
using System.Text.Json;
using MetaBrainz.Common.Json;
namespace MetaBrainz.MusicBrainz.Json;
internal static class HelperMethods {
public static TimeSpan? GetOptionalTimeSpanFromMilliseconds(this ref Utf8JsonReader reader) {
var ms = reader.GetOptionalDouble();
if (ms is null) {
return null;
}
return TimeSpan.FromMilliseconds(ms.Value);
}
public static EntityType ParseEntityType(string? text) => text switch {
"area" => EntityType.Area,
"artist" => EntityType.Artist,
"collection" => EntityType.Collection,
"event" => EntityType.Event,
"genre" => EntityType.Genre,
"instrument" => EntityType.Instrument,
"label" => EntityType.Label,
"place" => EntityType.Place,
"recording" => EntityType.Recording,
"release" => EntityType.Release,
"release-group" => EntityType.ReleaseGroup, // for Annotation
"release_group" => EntityType.ReleaseGroup, // for Collection and Relationship
"series" => EntityType.Series,
"url" => EntityType.Url,
"work" => EntityType.Work,
_ => EntityType.Unknown
};
}