2013-06-13 17:27:51 +01:00
|
|
|
|
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();
|
|
|
|
|
}
|
2013-06-14 16:19:26 +01:00
|
|
|
|
|
|
|
|
|
public static int ToInt(this bool b)
|
|
|
|
|
{
|
|
|
|
|
return b ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-14 17:44:55 +01:00
|
|
|
|
public static int ToUnixTimestamp(this DateTime dt)
|
2013-06-14 16:19:26 +01:00
|
|
|
|
{
|
2013-06-15 16:17:37 +01:00
|
|
|
|
var d = (dt - new DateTime(1970, 1, 1).ToUniversalTime()).TotalSeconds;
|
2013-06-14 17:44:55 +01:00
|
|
|
|
|
|
|
|
|
return Convert.ToInt32(d);
|
2013-06-14 16:19:26 +01:00
|
|
|
|
}
|
2013-06-15 16:17:37 +01:00
|
|
|
|
|
|
|
|
|
public static DateTime ToDateTimeUtc(this double stamp)
|
|
|
|
|
{
|
|
|
|
|
var d = new DateTime(1970, 1, 1).ToUniversalTime();
|
|
|
|
|
d = d.AddSeconds(stamp);
|
|
|
|
|
return d;
|
|
|
|
|
}
|
2013-06-13 17:27:51 +01:00
|
|
|
|
}
|
|
|
|
|
}
|