correct serialization of DateTime and Boolean values

This commit is contained in:
2013-09-18 21:14:07 +02:00
parent de1e4efc70
commit d009afd033
2 changed files with 16 additions and 2 deletions
+2 -2
View File
@@ -35,12 +35,12 @@ namespace PocketSharp.Tests
List<PocketItem> items = await client.Retrieve(
state: State.unread,
tag: "pocket",
contentType: ContentType.article,
sort: Sort.title,
since: new DateTime(2010, 12, 10),
count: 2
);
Assert.True(items.Count > 0);
Assert.InRange<int>(items.Count, 0, 2);
}
@@ -35,16 +35,30 @@ namespace PocketSharp.Models
string name = attribute.Name ?? propertyInfo.Name.ToLower();
object value = propertyInfo.GetValue(this, null);
// invalid parameter
if (value == null)
{
continue;
}
// convert array to comma-seperated list
if (value is IEnumerable && value.GetType().GetElementType() == typeof(string))
{
value = string.Join(",", ((IEnumerable)value).Cast<object>().Select(x => x.ToString()).ToArray());
}
// convert booleans
if (value is bool)
{
value = System.Convert.ToBoolean(value) ? "1" : "0";
}
// convert DateTime to UNIX timestamp
if (value is DateTime)
{
value = (int)((DateTime)value - new DateTime(1970, 1, 1)).TotalSeconds;
}
parameterDict.Add(name, value.ToString());
}