forked from JohnnyCrazy/SpotifyAPI-NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
39 lines (33 loc) · 1.04 KB
/
Util.cs
File metadata and controls
39 lines (33 loc) · 1.04 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
using System;
using System.Collections.Generic;
using System.Linq;
namespace SpotifyAPI.Web;
public static class Util
{
public static string GetStringAttribute<T>(this T en, string separator = "") where T : Enum, IConvertible
{
var attributes =
Enum.GetValues(typeof(T))
.Cast<T>()
.Where(v => en.HasFlag(v))
.Select(v => typeof(T).GetField(v.ToString()))
.Select(f => f.GetCustomAttributes(typeof(StringAttribute), false)[0])
.Cast<StringAttribute>();
List<string> list = [];
attributes.ToList().ForEach(element => list.Add(element.Text));
return string.Join(separator, list);
}
public static long ToUnixTimeMillisecondsPoly(this DateTime time)
{
return (long)time.Subtract(DateTime.UnixEpoch).TotalMilliseconds;
}
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public sealed class StringAttribute : Attribute
{
public string Text { get; set; }
public StringAttribute(string text)
{
Text = text;
}
}