mirror of
https://github.com/Sarsoo/IF.Lastfm.git
synced 2024-10-17 23:33:08 +01:00
48cdea2aea
Also updated demo app.
45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace IF.Lastfm.Core.Api.Helpers
|
|
{
|
|
public static class ApiExtensions
|
|
{
|
|
public static string GetApiName(this Enum en)
|
|
{
|
|
var type = en.GetType();
|
|
|
|
var memInfo = type.GetMember(en.ToString());
|
|
|
|
if (memInfo.Length > 0)
|
|
{
|
|
var attrs = memInfo[0].GetCustomAttributes(typeof (ApiNameAttribute), false);
|
|
|
|
if (attrs != null && attrs.Length > 0)
|
|
{
|
|
return ((ApiNameAttribute) attrs[0]).Text;
|
|
}
|
|
}
|
|
|
|
return en.ToString();
|
|
}
|
|
|
|
public static int ToInt(this bool b)
|
|
{
|
|
return b ? 1 : 0;
|
|
}
|
|
|
|
public static int ToUnixTimestamp(this DateTime dt)
|
|
{
|
|
var d = (dt - new DateTime(1970, 1, 1).ToUniversalTime()).TotalSeconds;
|
|
|
|
return Convert.ToInt32(d);
|
|
}
|
|
|
|
public static DateTime ToDateTimeUtc(this double stamp)
|
|
{
|
|
var d = new DateTime(1970, 1, 1).ToUniversalTime();
|
|
d = d.AddSeconds(stamp);
|
|
return d;
|
|
}
|
|
}
|
|
} |