forked from JohnnyCrazy/SpotifyAPI-NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTuneableTrack.cs
More file actions
74 lines (59 loc) · 2.06 KB
/
TuneableTrack.cs
File metadata and controls
74 lines (59 loc) · 2.06 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Newtonsoft.Json;
namespace SpotifyAPI.Web.Models
{
public class TuneableTrack
{
[String("acousticness")]
public float? Acousticness { get; set; }
[String("danceability")]
public float? Danceability { get; set; }
[String("duration_ms")]
public int? DurationMs { get; set; }
[String("energy")]
public float? Energy { get; set; }
[String("instrumentalness")]
public float? Instrumentalness { get; set; }
[String("key")]
public int? Key { get; set; }
[String("liveness")]
public float? Liveness { get; set; }
[String("loudness")]
public float? Loudness { get; set; }
[String("mode")]
public int? Mode { get; set; }
[String("popularity")]
public int? Popularity { get; set; }
[String("speechiness")]
public float? Speechiness { get; set; }
[String("tempo")]
public float? Tempo { get; set; }
[String("time_signature")]
public int? TimeSignature { get; set; }
[String("valence")]
public float? Valence { get; set; }
public string BuildUrlParams(string prefix)
{
List<string> urlParams = new List<string>();
foreach (PropertyInfo info in GetType().GetProperties())
{
object value = info.GetValue(this);
string name = info.GetCustomAttribute<StringAttribute>()?.Text;
if(name == null || value == null)
continue;
if (value is float)
urlParams.Add($"{prefix}_{name}={((float)value).ToString(CultureInfo.InvariantCulture)}");
else
urlParams.Add($"{prefix}_{name}={value}");
}
if (urlParams.Count > 0)
return "&" + string.Join("&", urlParams);
return "";
}
}
}