-Added JSON Schema implementation
-Move test serialization objects to TestObjects namespace -Fixed JsonConvert to always write a floating point number with a decimal place -Changed Type values to serialize and deserialize to type name string -Fixed JsonWriter to allow objects and arrays to be written in a constructor -Added JsonContainerAttribute with Id, Title and Description members. JsonObject and JsonArray inherit from this attribute -Added JsonArrayAttribute. Has flag to control whether array can contain null items. -Added IsRequired to JsonProperty -Replaced protected method GetSerializableMembers with GetMemberMappings on JsonSerializer -Fixed QuoteChar not getting set when parsing property name -Added Load(JsonReader) to JProperty, JConstructor -Fixed error when populating JProperty with content from collection -Added the ability for JsonTokenWriter to write individual values as well as arrays and objects -Added CreateReader to JToken -Added FromObject to JToken -Added ReadFrom to JToken
This commit is contained in:
@@ -354,16 +354,42 @@ namespace Newtonsoft.Json.Utilities
|
||||
|
||||
public static bool IsListType(Type type)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "listType");
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
|
||||
if (type.IsArray)
|
||||
return true;
|
||||
else if (typeof(IList).IsAssignableFrom(type))
|
||||
if (typeof(IList).IsAssignableFrom(type))
|
||||
return true;
|
||||
else if (ReflectionUtils.ImplementsGenericDefinition(type, typeof(IList<>)))
|
||||
if (ReflectionUtils.ImplementsGenericDefinition(type, typeof(IList<>)))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsCollectionType(Type type)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
|
||||
if (type.IsArray)
|
||||
return true;
|
||||
if (typeof(ICollection).IsAssignableFrom(type))
|
||||
return true;
|
||||
if (ReflectionUtils.ImplementsGenericDefinition(type, typeof(ICollection<>)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool IsDictionaryType(Type type)
|
||||
{
|
||||
ValidationUtils.ArgumentNotNull(type, "type");
|
||||
|
||||
if (typeof(IDictionary).IsAssignableFrom(type))
|
||||
return true;
|
||||
if (ReflectionUtils.ImplementsGenericDefinition(type, typeof (IDictionary<,>)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IWrappedCollection CreateCollectionWrapper(object list)
|
||||
@@ -538,5 +564,36 @@ namespace Newtonsoft.Json.Utilities
|
||||
Array.Copy(initial, 0, destinationArray, 0, initial.Length);
|
||||
return destinationArray;
|
||||
}
|
||||
|
||||
public static bool AddDistinct<T>(this IList<T> list, T value)
|
||||
{
|
||||
return list.AddDistinct(value, EqualityComparer<T>.Default);
|
||||
}
|
||||
|
||||
public static bool AddDistinct<T>(this IList<T> list, T value, IEqualityComparer<T> comparer)
|
||||
{
|
||||
if (list.Contains(value, comparer))
|
||||
return false;
|
||||
|
||||
list.Add(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool AddRangeDistinct<T>(this IList<T> list, IEnumerable<T> values)
|
||||
{
|
||||
return list.AddRangeDistinct(values, EqualityComparer<T>.Default);
|
||||
}
|
||||
|
||||
public static bool AddRangeDistinct<T>(this IList<T> list, IEnumerable<T> values, IEqualityComparer<T> comparer)
|
||||
{
|
||||
bool allAdded = true;
|
||||
foreach (T value in values)
|
||||
{
|
||||
if (!list.AddDistinct(value, comparer))
|
||||
allAdded = false;
|
||||
}
|
||||
|
||||
return allAdded;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user