move DictionaryToList into Utilities;
This commit is contained in:
@@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Serialization;
|
||||
using ServiceStack.Text;
|
||||
|
||||
namespace PocketSharp.Models
|
||||
{
|
||||
|
||||
@@ -79,13 +79,13 @@ namespace PocketSharp.Models
|
||||
[IgnoreDataMember]
|
||||
public List<PocketTag> Tags
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketTag>(_TagDictionary); }
|
||||
get { return Utilities.DictionaryToList<PocketTag>(_TagDictionary); }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketImage> Images
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketImage>(_ImageDictionary); }
|
||||
get { return Utilities.DictionaryToList<PocketImage>(_ImageDictionary); }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
@@ -97,13 +97,13 @@ namespace PocketSharp.Models
|
||||
[IgnoreDataMember]
|
||||
public List<PocketVideo> Videos
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketVideo>(_VideoDictionary); }
|
||||
get { return Utilities.DictionaryToList<PocketVideo>(_VideoDictionary); }
|
||||
}
|
||||
|
||||
[IgnoreDataMember]
|
||||
public List<PocketAuthor> Authors
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketAuthor>(_AuthorDictionary); }
|
||||
get { return Utilities.DictionaryToList<PocketAuthor>(_AuthorDictionary); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace PocketSharp.Models
|
||||
[IgnoreDataMember]
|
||||
public List<PocketItem> Items
|
||||
{
|
||||
get { return PocketClient.DictionaryToList<PocketItem>(_ItemDictionary); }
|
||||
get { return Utilities.DictionaryToList<PocketItem>(_ItemDictionary); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,30 +253,5 @@ namespace PocketSharp
|
||||
throw new APIException("Error retrieving response", response.ErrorException);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert a dictionary to a list
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <returns></returns>
|
||||
internal static List<T> DictionaryToList<T>(Dictionary<string, T> items) where T : new()
|
||||
{
|
||||
if(items == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var itemEnumerator = items.GetEnumerator();
|
||||
List<T> list = new List<T>();
|
||||
|
||||
while (itemEnumerator.MoveNext())
|
||||
{
|
||||
list.Add(itemEnumerator.Current.Value);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,5 +40,30 @@ namespace PocketSharp
|
||||
Type = type
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Convert a dictionary to a list
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="items">The items.</param>
|
||||
/// <returns></returns>
|
||||
public static List<T> DictionaryToList<T>(Dictionary<string, T> items) where T : new()
|
||||
{
|
||||
if (items == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var itemEnumerator = items.GetEnumerator();
|
||||
List<T> list = new List<T>();
|
||||
|
||||
while (itemEnumerator.MoveNext())
|
||||
{
|
||||
list.Add(itemEnumerator.Current.Value);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user