2014-07-20 21:42:46 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using SpotifyAPI.SpotifyWebAPI.Models;
|
|
|
|
|
|
|
|
|
|
namespace SpotifyAPI.SpotifyWebAPI
|
|
|
|
|
{
|
|
|
|
|
public static class Util
|
|
|
|
|
{
|
2015-02-12 23:23:07 +00:00
|
|
|
|
public static string GetStringAttribute<T>(this T en, String separator) where T : struct, IConvertible
|
2014-07-20 21:42:46 +01:00
|
|
|
|
{
|
2015-02-12 23:23:07 +00:00
|
|
|
|
Enum e = (Enum)(object)en;
|
2014-07-20 21:42:46 +01:00
|
|
|
|
IEnumerable<StringAttribute> attributes =
|
2015-02-12 23:23:07 +00:00
|
|
|
|
Enum.GetValues(typeof(T))
|
|
|
|
|
.Cast<T>()
|
|
|
|
|
.Where(v => e.HasFlag((Enum)(object)v))
|
|
|
|
|
.Select(v => typeof(T).GetField(v.ToString()))
|
2014-07-20 21:42:46 +01:00
|
|
|
|
.Select(f => f.GetCustomAttributes(typeof(StringAttribute), false)[0])
|
|
|
|
|
.Cast<StringAttribute>();
|
|
|
|
|
|
|
|
|
|
List<String> list = new List<String>();
|
|
|
|
|
attributes.ToList().ForEach((element) => list.Add(element.Text));
|
|
|
|
|
return string.Join(" ", list);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|