prevent creation of Lists and use IEnumerable where possible
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections.ObjectModel;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace PocketSharp.WP8.ViewModels
|
namespace PocketSharp.WP8.ViewModels
|
||||||
{
|
{
|
||||||
@@ -74,7 +75,7 @@ namespace PocketSharp.WP8.ViewModels
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
items = await client.Get();
|
items = (await client.Get()).ToList();
|
||||||
|
|
||||||
items.ForEach(item =>
|
items.ForEach(item =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace PocketSharp.Wpf
|
namespace PocketSharp.Wpf
|
||||||
{
|
{
|
||||||
@@ -40,7 +41,7 @@ namespace PocketSharp.Wpf
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
items = await client.Get();
|
items = (await client.Get()).ToList();
|
||||||
|
|
||||||
items.ForEach(item =>
|
items.ForEach(item =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace PocketSharp.Tests
|
namespace PocketSharp.Tests
|
||||||
{
|
{
|
||||||
@@ -47,7 +48,7 @@ namespace PocketSharp.Tests
|
|||||||
tweetID: "380051788172632065"
|
tweetID: "380051788172632065"
|
||||||
);
|
);
|
||||||
|
|
||||||
List<PocketItem> items = await client.Get();
|
List<PocketItem> items = (await client.Get()).ToList();
|
||||||
PocketItem itemDesired = null;
|
PocketItem itemDesired = null;
|
||||||
|
|
||||||
items.ForEach(itm =>
|
items.ForEach(itm =>
|
||||||
@@ -60,7 +61,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
Assert.NotNull(itemDesired);
|
Assert.NotNull(itemDesired);
|
||||||
Assert.Equal(itemDesired.ID, item.ID);
|
Assert.Equal(itemDesired.ID, item.ID);
|
||||||
Assert.Equal(itemDesired.Tags.Count, 3);
|
Assert.Equal(itemDesired.Tags.Count(), 3);
|
||||||
|
|
||||||
itemsToDelete.Add(item.ID);
|
itemsToDelete.Add(item.ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace PocketSharp.Tests
|
namespace PocketSharp.Tests
|
||||||
{
|
{
|
||||||
@@ -16,7 +17,7 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task AreItemsRetrieved()
|
public async Task AreItemsRetrieved()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get();
|
List<PocketItem> items = (await client.Get()).ToList();
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task IsItemRetrievedById()
|
public async Task IsItemRetrievedById()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get();
|
List<PocketItem> items = (await client.Get()).ToList();
|
||||||
PocketItem item = items[0];
|
PocketItem item = items[0];
|
||||||
PocketItem itemDuplicate = await client.Get(item.ID);
|
PocketItem itemDuplicate = await client.Get(item.ID);
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task IsItemJsonPopulated()
|
public async Task IsItemJsonPopulated()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get();
|
List<PocketItem> items = (await client.Get()).ToList();
|
||||||
string schemaJson = @"{
|
string schemaJson = @"{
|
||||||
'description': 'PocketItem',
|
'description': 'PocketItem',
|
||||||
'type': 'object'
|
'type': 'object'
|
||||||
@@ -53,16 +54,16 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task AreFilteredItemsRetrieved()
|
public async Task AreFilteredItemsRetrieved()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(RetrieveFilter.Favorite);
|
IEnumerable<PocketItem> items = await client.Get(RetrieveFilter.Favorite);
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RetrieveWithMultipleFilters()
|
public async Task RetrieveWithMultipleFilters()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(
|
IEnumerable<PocketItem> items = await client.Get(
|
||||||
state: State.unread,
|
state: State.unread,
|
||||||
tag: "pocket",
|
tag: "pocket",
|
||||||
sort: Sort.title,
|
sort: Sort.title,
|
||||||
@@ -70,29 +71,29 @@ namespace PocketSharp.Tests
|
|||||||
count: 2
|
count: 2
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.InRange<int>(items.Count, 0, 2);
|
Assert.InRange<int>(items.Count(), 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task ItemContainsUri()
|
public async Task ItemContainsUri()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 1);
|
IEnumerable<PocketItem> items = await client.Get(count: 1);
|
||||||
|
|
||||||
Assert.True(items.Count == 1);
|
Assert.True(items.Count() == 1);
|
||||||
Assert.True(items[0].Uri.ToString().StartsWith("http"));
|
Assert.True(items.First().Uri.ToString().StartsWith("http"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InvalidRetrievalReturnsNoResults()
|
public async Task InvalidRetrievalReturnsNoResults()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(
|
IEnumerable<PocketItem> items = await client.Get(
|
||||||
favorite: true,
|
favorite: true,
|
||||||
search: "xoiu987a#;"
|
search: "xoiu987a#;"
|
||||||
);
|
);
|
||||||
|
|
||||||
Assert.False(items.Count > 0);
|
Assert.False(items.Count() > 0);
|
||||||
|
|
||||||
PocketItem item = await client.Get("99999999");
|
PocketItem item = await client.Get("99999999");
|
||||||
|
|
||||||
@@ -100,48 +101,48 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
items = await client.Get(RetrieveFilter.Video);
|
items = await client.Get(RetrieveFilter.Video);
|
||||||
|
|
||||||
Assert.False(items.Count > 0);
|
Assert.False(items.Count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SearchReturnsResult()
|
public async Task SearchReturnsResult()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Search("pocket");
|
IEnumerable<PocketItem> items = await client.Search("pocket");
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
Assert.True(items[0].FullTitle.ToLower().Contains("pocket"));
|
Assert.True(items.First().FullTitle.ToLower().Contains("pocket"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task InvalidSearchReturnsNoResult()
|
public async Task InvalidSearchReturnsNoResult()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Search("adsüasd-opiu2;.398dfyx");
|
IEnumerable<PocketItem> items = await client.Search("adsüasd-opiu2;.398dfyx");
|
||||||
|
|
||||||
Assert.False(items.Count > 0);
|
Assert.False(items.Count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task RetrieveTagsReturnsResult()
|
public async Task RetrieveTagsReturnsResult()
|
||||||
{
|
{
|
||||||
List<PocketTag> items = await client.GetTags();
|
IEnumerable<PocketTag> items = await client.GetTags();
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task SearchByTagsReturnsResult()
|
public async Task SearchByTagsReturnsResult()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.SearchByTag("pocket");
|
IEnumerable<PocketItem> items = await client.SearchByTag("pocket");
|
||||||
|
|
||||||
Assert.True(items.Count == 1);
|
Assert.True(items.Count() == 1);
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
items[0].Tags.ForEach(tag =>
|
items.First().Tags.ToList().ForEach(tag =>
|
||||||
{
|
{
|
||||||
if (tag.Name.Contains("pocket"))
|
if (tag.Name.Contains("pocket"))
|
||||||
{
|
{
|
||||||
@@ -156,9 +157,9 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task InvalidSearchByTagsReturnsNoResult()
|
public async Task InvalidSearchByTagsReturnsNoResult()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.SearchByTag("adsüasd-opiu2;.398dfyx");
|
IEnumerable<PocketItem> items = await client.SearchByTag("adsüasd-opiu2;.398dfyx");
|
||||||
|
|
||||||
Assert.False(items.Count > 0);
|
Assert.False(items.Count() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -183,10 +184,10 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task IsNewPocketItemListGeneratorWorking()
|
public async Task IsNewPocketItemListGeneratorWorking()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 1, tag: "pocket");
|
IEnumerable<PocketItem> items = await client.Get(count: 1, tag: "pocket");
|
||||||
PocketItem item = items[0];
|
PocketItem item = items.First();
|
||||||
|
|
||||||
Assert.True(item.Tags.Find(i => i.Name == "pocket") != null);
|
Assert.True(item.Tags.ToList().Find(i => i.Name == "pocket") != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,20 +196,20 @@ namespace PocketSharp.Tests
|
|||||||
{
|
{
|
||||||
DateTime since = DateTime.UtcNow;
|
DateTime since = DateTime.UtcNow;
|
||||||
|
|
||||||
List<PocketItem> items = await client.Get(state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(state: State.all);
|
||||||
PocketItem itemToModify = items[0];
|
PocketItem itemToModify = items.First();
|
||||||
|
|
||||||
Assert.True(items.Count >= 3);
|
Assert.True(items.Count() >= 3);
|
||||||
|
|
||||||
items = await client.Get(state: State.all, since: since);
|
items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
Assert.True(items == null || items.Count == 0);
|
Assert.True(items == null || items.Count() == 0);
|
||||||
|
|
||||||
await client.AddTags(itemToModify, new string[] { "pocketsharp" });
|
await client.AddTags(itemToModify, new string[] { "pocketsharp" });
|
||||||
|
|
||||||
items = await client.Get(state: State.all, since: since);
|
items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
|
|
||||||
await client.RemoveTags(itemToModify, new string[] { "pocketsharp" });
|
await client.RemoveTags(itemToModify, new string[] { "pocketsharp" });
|
||||||
}
|
}
|
||||||
@@ -219,20 +220,20 @@ namespace PocketSharp.Tests
|
|||||||
{
|
{
|
||||||
DateTime since = DateTime.UtcNow;
|
DateTime since = DateTime.UtcNow;
|
||||||
|
|
||||||
List<PocketItem> items = await client.Get(state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(state: State.all);
|
||||||
PocketItem itemToModify = items[0];
|
PocketItem itemToModify = items.First();
|
||||||
|
|
||||||
Assert.True(items.Count >= 3);
|
Assert.True(items.Count() >= 3);
|
||||||
|
|
||||||
items = await client.Get(state: State.all, since: since);
|
items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
Assert.True(items == null || items.Count == 0);
|
Assert.True(items == null || items.Count() == 0);
|
||||||
|
|
||||||
await client.Favorite(itemToModify);
|
await client.Favorite(itemToModify);
|
||||||
|
|
||||||
items = await client.Get(state: State.all, since: since);
|
items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
|
|
||||||
await client.Unfavorite(itemToModify);
|
await client.Unfavorite(itemToModify);
|
||||||
|
|
||||||
@@ -242,7 +243,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
items = await client.Get(state: State.all, since: since);
|
items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
|
|
||||||
await client.Unarchive(itemToModify);
|
await client.Unarchive(itemToModify);
|
||||||
}
|
}
|
||||||
@@ -255,7 +256,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
PocketItem item = await client.Add(new Uri("http://frontendplay.com"));
|
PocketItem item = await client.Add(new Uri("http://frontendplay.com"));
|
||||||
|
|
||||||
List<PocketItem> items = await client.Get(state: State.all, since: since);
|
IEnumerable<PocketItem> items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
since = DateTime.UtcNow;
|
since = DateTime.UtcNow;
|
||||||
|
|
||||||
@@ -263,7 +264,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
items = await client.Get(state: State.all, since: since);
|
items = await client.Get(state: State.all, since: since);
|
||||||
|
|
||||||
Assert.True(items.Count == 1 && items[0].IsDeleted);
|
Assert.True(items.Count() == 1 && items.First().IsDeleted);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -271,11 +272,11 @@ namespace PocketSharp.Tests
|
|||||||
{
|
{
|
||||||
PocketItem item = await client.Add(new Uri("http://de.ign.com/m/feature/21608/die-20-besten-kurzfilme-des-jahres-2013?bust=1"));
|
PocketItem item = await client.Add(new Uri("http://de.ign.com/m/feature/21608/die-20-besten-kurzfilme-des-jahres-2013?bust=1"));
|
||||||
|
|
||||||
List<PocketItem> items = await client.Get(state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(state: State.all);
|
||||||
|
|
||||||
Assert.NotNull(item.Uri);
|
Assert.NotNull(item.Uri);
|
||||||
Assert.NotNull(items[0].Uri);
|
Assert.NotNull(items.First().Uri);
|
||||||
Assert.Equal(item.Uri, items[0].Uri);
|
Assert.Equal(item.Uri, items.First().Uri);
|
||||||
|
|
||||||
itemsToDelete.Add(item.ID);
|
itemsToDelete.Add(item.ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace PocketSharp.Tests
|
namespace PocketSharp.Tests
|
||||||
{
|
{
|
||||||
@@ -19,8 +20,8 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CheckPreRequestAction()
|
public async Task CheckPreRequestAction()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 1);
|
IEnumerable<PocketItem> items = await client.Get(count: 1);
|
||||||
PocketItem item = items[0];
|
PocketItem item = items.First();
|
||||||
|
|
||||||
await client.Favorite(item);
|
await client.Favorite(item);
|
||||||
await client.Unfavorite(item);
|
await client.Unfavorite(item);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
item = await GetItemById(item.ID);
|
item = await GetItemById(item.ID);
|
||||||
|
|
||||||
Assert.True(item.Tags.Count >= 2);
|
Assert.True(item.Tags.Count() >= 2);
|
||||||
|
|
||||||
Assert.NotNull(item.Tags.Single<PocketTag>(tag => tag.Name == "test_tag"));
|
Assert.NotNull(item.Tags.Single<PocketTag>(tag => tag.Name == "test_tag"));
|
||||||
Assert.NotNull(item.Tags.Single<PocketTag>(tag => tag.Name == "test_tag2"));
|
Assert.NotNull(item.Tags.Single<PocketTag>(tag => tag.Name == "test_tag2"));
|
||||||
@@ -44,7 +44,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
item = await GetItemById(item.ID);
|
item = await GetItemById(item.ID);
|
||||||
|
|
||||||
Assert.True(item.Tags.Count >= 2);
|
Assert.True(item.Tags.Count() >= 2);
|
||||||
|
|
||||||
Assert.True(await client.RemoveTags(item));
|
Assert.True(await client.RemoveTags(item));
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
item = await GetItemById(item.ID);
|
item = await GetItemById(item.ID);
|
||||||
|
|
||||||
Assert.Equal(item.Tags.Count, 2);
|
Assert.Equal(item.Tags.Count(), 2);
|
||||||
|
|
||||||
Assert.NotNull(item.Tags.SingleOrDefault<PocketTag>(tag => tag.Name == "test_tag"));
|
Assert.NotNull(item.Tags.SingleOrDefault<PocketTag>(tag => tag.Name == "test_tag"));
|
||||||
Assert.NotNull(item.Tags.SingleOrDefault<PocketTag>(tag => tag.Name == "test_tag2"));
|
Assert.NotNull(item.Tags.SingleOrDefault<PocketTag>(tag => tag.Name == "test_tag2"));
|
||||||
@@ -85,7 +85,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
private async Task<PocketItem> GetItemById(string id, bool archive = false)
|
private async Task<PocketItem> GetItemById(string id, bool archive = false)
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(state: archive ? State.archive : State.unread);
|
List<PocketItem> items = (await client.Get(state: archive ? State.archive : State.unread)).ToList();
|
||||||
PocketItem itemDesired = null;
|
PocketItem itemDesired = null;
|
||||||
|
|
||||||
items.ForEach(itm =>
|
items.ForEach(itm =>
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace PocketSharp.Tests
|
|||||||
|
|
||||||
private async Task<PocketItem> GetItemById(string id, bool archive = false)
|
private async Task<PocketItem> GetItemById(string id, bool archive = false)
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(state: archive ? State.archive : State.unread);
|
List<PocketItem> items = (await client.Get(state: archive ? State.archive : State.unread)).ToList();
|
||||||
PocketItem itemDesired = null;
|
PocketItem itemDesired = null;
|
||||||
|
|
||||||
items.ForEach(itm =>
|
items.ForEach(itm =>
|
||||||
|
|||||||
@@ -30,50 +30,50 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task Are100ItemsRetrievedProperly()
|
public async Task Are100ItemsRetrievedProperly()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 100, state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(count: 100, state: State.all);
|
||||||
Assert.True(items.Count == 100);
|
Assert.True(items.Count() == 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Are1000ItemsRetrievedProperly()
|
public async Task Are1000ItemsRetrievedProperly()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 1000, state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(count: 1000, state: State.all);
|
||||||
Assert.True(items.Count == 1000);
|
Assert.True(items.Count() == 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Are2500ItemsRetrievedProperly()
|
public async Task Are2500ItemsRetrievedProperly()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 2500, state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(count: 2500, state: State.all);
|
||||||
Assert.True(items.Count == 2500);
|
Assert.True(items.Count() == 2500);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Are5000ItemsRetrievedProperly()
|
public async Task Are5000ItemsRetrievedProperly()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(count: 5000, state: State.all);
|
IEnumerable<PocketItem> items = await client.Get(count: 5000, state: State.all);
|
||||||
Assert.True(items.Count == 5000);
|
Assert.True(items.Count() == 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task IsSearchSuccessfullyOnBigList()
|
public async Task IsSearchSuccessfullyOnBigList()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.Get(search: "google");
|
IEnumerable<PocketItem> items = await client.Get(search: "google");
|
||||||
|
|
||||||
Assert.True(items.Count > 0);
|
Assert.True(items.Count() > 0);
|
||||||
Assert.True(items[0].Title.ToLower().Contains("google") || items[0].Uri.ToString().ToLower().Contains("google"));
|
Assert.True(items.First().Title.ToLower().Contains("google") || items.First().Uri.ToString().ToLower().Contains("google"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task IsTagSearchSuccessfullyOnBigList()
|
public async Task IsTagSearchSuccessfullyOnBigList()
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await client.SearchByTag(tags[0]);
|
IEnumerable<PocketItem> items = await client.SearchByTag(tags[0]);
|
||||||
|
|
||||||
Assert.True(items.Count > 1);
|
Assert.True(items.Count() > 1);
|
||||||
|
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
items[0].Tags.ForEach(tag =>
|
items.First().Tags.ToList().ForEach(tag =>
|
||||||
{
|
{
|
||||||
if (tag.Name.Contains(tags[0]))
|
if (tag.Name.Contains(tags[0]))
|
||||||
{
|
{
|
||||||
@@ -87,7 +87,7 @@ namespace PocketSharp.Tests
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task RetrieveTagsReturnsResultOnBigList()
|
public async Task RetrieveTagsReturnsResultOnBigList()
|
||||||
{
|
{
|
||||||
List<PocketTag> items = await client.GetTags();
|
List<PocketTag> items = (await client.GetTags()).ToList();
|
||||||
|
|
||||||
items.ForEach(tag =>
|
items.ForEach(tag =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<List<PocketItem>> Get(
|
public async Task<IEnumerable<PocketItem>> Get(
|
||||||
State? state = null,
|
State? state = null,
|
||||||
bool? favorite = null,
|
bool? favorite = null,
|
||||||
string tag = null,
|
string tag = null,
|
||||||
@@ -58,9 +58,7 @@ namespace PocketSharp
|
|||||||
Offset = offset
|
Offset = offset
|
||||||
};
|
};
|
||||||
|
|
||||||
Retrieve response = await Request<Retrieve>("get", cancellationToken, parameters.Convert());
|
return (await Request<Retrieve>("get", cancellationToken, parameters.Convert())).Items;
|
||||||
|
|
||||||
return response.Items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,12 +72,10 @@ namespace PocketSharp
|
|||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<PocketItem> Get(string itemID, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<PocketItem> Get(string itemID, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await Get(
|
return (await Get(
|
||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken,
|
||||||
state: State.all
|
state: State.all
|
||||||
);
|
)).SingleOrDefault<PocketItem>(item => item.ID == itemID);
|
||||||
|
|
||||||
return items.SingleOrDefault<PocketItem>(item => item.ID == itemID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -90,7 +86,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<List<PocketItem>> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<IEnumerable<PocketItem>> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
RetrieveParameters parameters = new RetrieveParameters();
|
RetrieveParameters parameters = new RetrieveParameters();
|
||||||
|
|
||||||
@@ -121,9 +117,7 @@ namespace PocketSharp
|
|||||||
|
|
||||||
parameters.DetailType = DetailType.complete;
|
parameters.DetailType = DetailType.complete;
|
||||||
|
|
||||||
Retrieve response = await Request<Retrieve>("get", cancellationToken, parameters.Convert());
|
return (await Request<Retrieve>("get", cancellationToken, parameters.Convert())).Items;
|
||||||
|
|
||||||
return response.Items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -134,18 +128,19 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<List<PocketTag>> GetTags(CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<IEnumerable<PocketTag>> GetTags(CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
List<PocketItem> items = await Get(
|
IEnumerable<PocketItem> items = await Get(
|
||||||
cancellationToken: cancellationToken,
|
cancellationToken: cancellationToken,
|
||||||
state: State.all
|
state: State.all
|
||||||
);
|
);
|
||||||
|
|
||||||
return items.Where(item => item.Tags != null)
|
return items
|
||||||
.SelectMany(item => item.Tags)
|
.Where(item => item.Tags != null)
|
||||||
.GroupBy(item => item.Name)
|
.SelectMany(item => item.Tags)
|
||||||
.Select(item => item.First())
|
.GroupBy(item => item.Name)
|
||||||
.ToList<PocketTag>();
|
.Select(item => item.First())
|
||||||
|
.ToList<PocketTag>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +151,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<List<PocketItem>> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<IEnumerable<PocketItem>> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
return await Get(
|
return await Get(
|
||||||
state: State.all,
|
state: State.all,
|
||||||
@@ -175,7 +170,7 @@ namespace PocketSharp
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
|
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<List<PocketItem>> Search(string searchString, string tag = null, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<IEnumerable<PocketItem>> Search(string searchString, string tag = null, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
if (String.IsNullOrEmpty(searchString) || searchString.Length < 2)
|
if (String.IsNullOrEmpty(searchString) || searchString.Length < 2)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
public async Task<bool> SendActions(List<PocketAction> actions, CancellationToken cancellationToken = default(CancellationToken))
|
public async Task<bool> SendActions(IEnumerable<PocketAction> actions, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
{
|
{
|
||||||
return await Send(actions, cancellationToken);
|
return await Send(actions, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<List<PocketItem>> Get(
|
Task<IEnumerable<PocketItem>> Get(
|
||||||
State? state = null,
|
State? state = null,
|
||||||
bool? favorite = null,
|
bool? favorite = null,
|
||||||
string tag = null,
|
string tag = null,
|
||||||
@@ -158,7 +158,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<List<PocketItem>> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken));
|
Task<IEnumerable<PocketItem>> Get(RetrieveFilter filter, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves all available tags.
|
/// Retrieves all available tags.
|
||||||
@@ -167,7 +167,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<List<PocketTag>> GetTags(CancellationToken cancellationToken = default(CancellationToken));
|
Task<IEnumerable<PocketTag>> GetTags(CancellationToken cancellationToken = default(CancellationToken));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves items by tag
|
/// Retrieves items by tag
|
||||||
@@ -176,7 +176,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<List<PocketItem>> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken));
|
Task<IEnumerable<PocketItem>> SearchByTag(string tag, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves items which match the specified search string in title and URI
|
/// Retrieves items which match the specified search string in title and URI
|
||||||
@@ -187,7 +187,7 @@ namespace PocketSharp
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
|
/// <exception cref="System.ArgumentOutOfRangeException">Search string length has to be a minimum of 2 chars</exception>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<List<PocketItem>> Search(string searchString, string tag = null, CancellationToken cancellationToken = default(CancellationToken));
|
Task<IEnumerable<PocketItem>> Search(string searchString, string tag = null, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region modify methods
|
#region modify methods
|
||||||
@@ -199,7 +199,7 @@ namespace PocketSharp
|
|||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="PocketException"></exception>
|
/// <exception cref="PocketException"></exception>
|
||||||
Task<bool> SendActions(List<PocketAction> actions, CancellationToken cancellationToken = default(CancellationToken));
|
Task<bool> SendActions(IEnumerable<PocketAction> actions, CancellationToken cancellationToken = default(CancellationToken));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Archives the specified item.
|
/// Archives the specified item.
|
||||||
|
|||||||
@@ -16,6 +16,6 @@ namespace PocketSharp.Models
|
|||||||
/// The actions.
|
/// The actions.
|
||||||
/// </value>
|
/// </value>
|
||||||
[DataMember(Name = "actions")]
|
[DataMember(Name = "actions")]
|
||||||
public List<Dictionary<string, string>> Actions { get; set; }
|
public IEnumerable<Dictionary<string, string>> Actions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
namespace PocketSharp.Models
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// All parameters which can be passed to register a user
|
|
||||||
/// </summary>
|
|
||||||
[DataContract]
|
|
||||||
internal class RegisterParameters : Parameters
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the username.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The username.
|
|
||||||
/// </value>
|
|
||||||
[DataMember(Name = "username")]
|
|
||||||
public string Username { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the E-Mail.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The E-Mail.
|
|
||||||
/// </value>
|
|
||||||
[DataMember(Name = "email")]
|
|
||||||
public string Email { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the password.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>
|
|
||||||
/// The password.
|
|
||||||
/// </value>
|
|
||||||
[DataMember(Name = "password")]
|
|
||||||
public string Password { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -322,7 +322,7 @@ namespace PocketSharp.Models
|
|||||||
/// </value>
|
/// </value>
|
||||||
[JsonProperty("tags")]
|
[JsonProperty("tags")]
|
||||||
[JsonConverter(typeof(ObjectToArrayConverter<PocketTag>))]
|
[JsonConverter(typeof(ObjectToArrayConverter<PocketTag>))]
|
||||||
public List<PocketTag> Tags { get; set; }
|
public IEnumerable<PocketTag> Tags { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the images.
|
/// Gets or sets the images.
|
||||||
@@ -332,7 +332,7 @@ namespace PocketSharp.Models
|
|||||||
/// </value>
|
/// </value>
|
||||||
[JsonProperty("images")]
|
[JsonProperty("images")]
|
||||||
[JsonConverter(typeof(ObjectToArrayConverter<PocketImage>))]
|
[JsonConverter(typeof(ObjectToArrayConverter<PocketImage>))]
|
||||||
public List<PocketImage> Images { get; set; }
|
public IEnumerable<PocketImage> Images { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the videos.
|
/// Gets or sets the videos.
|
||||||
@@ -342,7 +342,7 @@ namespace PocketSharp.Models
|
|||||||
/// </value>
|
/// </value>
|
||||||
[JsonProperty("videos")]
|
[JsonProperty("videos")]
|
||||||
[JsonConverter(typeof(ObjectToArrayConverter<PocketVideo>))]
|
[JsonConverter(typeof(ObjectToArrayConverter<PocketVideo>))]
|
||||||
public List<PocketVideo> Videos { get; set; }
|
public IEnumerable<PocketVideo> Videos { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the authors.
|
/// Gets or sets the authors.
|
||||||
@@ -352,7 +352,7 @@ namespace PocketSharp.Models
|
|||||||
/// </value>
|
/// </value>
|
||||||
[JsonProperty("authors")]
|
[JsonProperty("authors")]
|
||||||
[JsonConverter(typeof(ObjectToArrayConverter<PocketAuthor>))]
|
[JsonConverter(typeof(ObjectToArrayConverter<PocketAuthor>))]
|
||||||
public List<PocketAuthor> Authors { get; set; }
|
public IEnumerable<PocketAuthor> Authors { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the lead image.
|
/// Gets the lead image.
|
||||||
@@ -363,7 +363,7 @@ namespace PocketSharp.Models
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public PocketImage LeadImage
|
public PocketImage LeadImage
|
||||||
{
|
{
|
||||||
get { return Images != null && Images.Count > 0 ? Images[0] : null; }
|
get { return Images != null && Images.Count() > 0 ? Images.First() : null; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -36,6 +36,6 @@ namespace PocketSharp.Models
|
|||||||
/// </value>
|
/// </value>
|
||||||
[JsonProperty("list")]
|
[JsonProperty("list")]
|
||||||
[JsonConverter(typeof(ObjectToArrayConverter<PocketItem>))]
|
[JsonConverter(typeof(ObjectToArrayConverter<PocketItem>))]
|
||||||
public List<PocketItem> Items { get; set; }
|
public IEnumerable<PocketItem> Items { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using System.Net.Http;
|
|||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace PocketSharp
|
namespace PocketSharp
|
||||||
{
|
{
|
||||||
@@ -245,22 +246,13 @@ namespace PocketSharp
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="actionParameters">The action parameters.</param>
|
/// <param name="actionParameters">The action parameters.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal async Task<bool> Send(List<PocketAction> actionParameters, CancellationToken cancellationToken)
|
internal async Task<bool> Send(IEnumerable<PocketAction> actionParameters, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
List<Dictionary<string, object>> actionParamList = new List<Dictionary<string, object>>();
|
|
||||||
|
|
||||||
foreach (var action in actionParameters)
|
|
||||||
{
|
|
||||||
actionParamList.Add(action.Convert());
|
|
||||||
}
|
|
||||||
|
|
||||||
Dictionary<string, string> parameters = new Dictionary<string, string>() {{
|
Dictionary<string, string> parameters = new Dictionary<string, string>() {{
|
||||||
"actions", JsonConvert.SerializeObject(actionParamList)
|
"actions", JsonConvert.SerializeObject(actionParameters.Select(action => action.Convert()))
|
||||||
}};
|
}};
|
||||||
|
|
||||||
Modify response = await Request<Modify>("send", cancellationToken, parameters);
|
return (await Request<Modify>("send", cancellationToken, parameters)).Status;
|
||||||
|
|
||||||
return response.Status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Components\Statistics.cs" />
|
<Compile Include="Components\Statistics.cs" />
|
||||||
<Compile Include="IPocketClient.cs" />
|
<Compile Include="IPocketClient.cs" />
|
||||||
<Compile Include="Models\Parameters\RegisterParameters.cs" />
|
|
||||||
<Compile Include="Models\PocketBoolean.cs" />
|
<Compile Include="Models\PocketBoolean.cs" />
|
||||||
<Compile Include="Models\PocketLimits.cs" />
|
<Compile Include="Models\PocketLimits.cs" />
|
||||||
<Compile Include="Models\PocketStatistics.cs" />
|
<Compile Include="Models\PocketStatistics.cs" />
|
||||||
|
|||||||
@@ -123,17 +123,17 @@ namespace PocketSharp
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class ObjectToArrayConverter<T> : CustomCreationConverter<List<T>> where T : new()
|
public class ObjectToArrayConverter<T> : CustomCreationConverter<IEnumerable<T>> where T : new()
|
||||||
{
|
{
|
||||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
JObject jObject;
|
JObject jObject;
|
||||||
List<T> result = new List<T>();
|
List<T> results = new List<T>();
|
||||||
T target;
|
|
||||||
// object is an array
|
// object is an array
|
||||||
if (reader.TokenType == JsonToken.StartArray)
|
if (reader.TokenType == JsonToken.StartArray)
|
||||||
{
|
{
|
||||||
return serializer.Deserialize<List<T>>(reader);
|
return serializer.Deserialize<IEnumerable<T>>(reader);
|
||||||
}
|
}
|
||||||
else if (reader.TokenType == JsonToken.Null)
|
else if (reader.TokenType == JsonToken.Null)
|
||||||
{
|
{
|
||||||
@@ -152,11 +152,12 @@ namespace PocketSharp
|
|||||||
// Populate the object properties
|
// Populate the object properties
|
||||||
foreach (KeyValuePair<string, JToken> item in jObject)
|
foreach (KeyValuePair<string, JToken> item in jObject)
|
||||||
{
|
{
|
||||||
target = serializer.Deserialize<T>(item.Value.CreateReader());
|
results.Add(
|
||||||
result.Add(target);
|
serializer.Deserialize<T>(item.Value.CreateReader())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
@@ -164,11 +165,10 @@ namespace PocketSharp
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<T> Create(Type objectType)
|
public override IEnumerable<T> Create(Type objectType)
|
||||||
{
|
{
|
||||||
return new List<T>();
|
return new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user