correct serialization of DateTime and Boolean values
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user