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
44 lines (37 loc) · 1.22 KB
/
Copy pathUtil.cs
File metadata and controls
44 lines (37 loc) · 1.22 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
namespace SpotifyAPI.PCL.Web
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
public static class Util
{
public static string GetStringAttribute<T>(this T en, string separator) where T : struct
{
Enum e = (Enum)(object)en;
IEnumerable<StringAttribute> attributes =
Enum.GetValues(typeof(T))
.Cast<T>()
.Where(v => e.HasFlag((Enum)(object)v))
.Select(v => typeof(T).GetTypeInfo().GetDeclaredField(Convert.ToString(v, CultureInfo.InvariantCulture)))
.Select(f => f.GetCustomAttributes(typeof(StringAttribute), false).FirstOrDefault())
.Cast<StringAttribute>();
List<string> list = new List<string>();
attributes.ToList();
foreach (var element in attributes)
{
list.Add(element.Text);
}
return string.Join(separator, list);
}
}
public sealed class StringAttribute : Attribute
{
public string Text { get; set; }
public StringAttribute(string text)
{
this.Text = text;
}
}
}