-
Notifications
You must be signed in to change notification settings - Fork 0
/
LastFMArtistCorrection.cs
104 lines (87 loc) · 2.96 KB
/
LastFMArtistCorrection.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
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
// Generated by https://LastFM.ReaderCore.io
namespace LastFM.ReaderCore
{
using System;
using System.Collections.Generic;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public partial class LastFMArtistCorrection
{
[JsonProperty("corrections")]
public Corrections Corrections { get; set; }
}
public partial class Corrections
{
[JsonProperty("correction")]
public Correction Correction { get; set; }
}
public partial class Correction
{
[JsonProperty("artist")]
public Artist Artist { get; set; }
[JsonProperty("@attr")]
public ArtistAttr Attr { get; set; }
}
public partial class ArtistInfo
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("mbid")]
public Guid Mbid { get; set; }
[JsonProperty("url")]
public Uri Url { get; set; }
}
public partial class ArtistAttr
{
[JsonProperty("index")]
[JsonConverter(typeof(ParseStringConverter))]
public long Index { get; set; }
}
public partial class Test
{
public static Test FromJson(string json) => JsonConvert.DeserializeObject<Test>(json, LastFM.ReaderCore.Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this Test self) => JsonConvert.SerializeObject(self, LastFM.ReaderCore.Converter.Settings);
}
internal static class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
Converters = {
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal }
},
};
}
internal class ParseStringConverter : JsonConverter
{
public override bool CanConvert(Type t) => t == typeof(long) || t == typeof(long?);
public override object ReadJson(JsonReader reader, Type t, object existingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null) return null;
var value = serializer.Deserialize<string>(reader);
long l;
if (Int64.TryParse(value, out l))
{
return l;
}
throw new Exception("Cannot unmarshal type long");
}
public override void WriteJson(JsonWriter writer, object untypedValue, JsonSerializer serializer)
{
if (untypedValue == null)
{
serializer.Serialize(writer, null);
return;
}
var value = (long)untypedValue;
serializer.Serialize(writer, value.ToString());
return;
}
public static readonly ParseStringConverter Singleton = new ParseStringConverter();
}
}