-Added missing files from Silverlight projects
-Fixed JsonWriter depth error when writing current JsonReader position -Fixed JsonSerializer not fulling skipping properties when putting together constructor values -Changed JsonSerializer so that property names and constructor params matching is no longer case sensitive
This commit is contained in:
@@ -495,6 +495,7 @@ namespace Newtonsoft.Json
|
||||
if (c == null)
|
||||
throw new JsonSerializationException("Could not find a public constructor for type {0}.".FormatWith(CultureInfo.InvariantCulture, objectType));
|
||||
|
||||
// create a dictionary to put retrieved values into
|
||||
IDictionary<ParameterInfo, object> constructorParameters = c.GetParameters().ToDictionary(p => p, p => (object)null);
|
||||
|
||||
bool exit = false;
|
||||
@@ -504,16 +505,15 @@ namespace Newtonsoft.Json
|
||||
{
|
||||
case JsonToken.PropertyName:
|
||||
string memberName = reader.Value.ToString();
|
||||
ParameterInfo matchingConstructorParameter = constructorParameters
|
||||
.Where(kv => kv.Key.Name == memberName)
|
||||
.Select(kv => kv.Key)
|
||||
.SingleOrDefault();
|
||||
ParameterInfo matchingConstructorParameter = constructorParameters.ForgivingCaseSensitiveFind(kv => kv.Key.Name, memberName).Key;
|
||||
|
||||
if (!reader.Read())
|
||||
throw new JsonSerializationException("Unexpected end when setting {0}'s value.".FormatWith(CultureInfo.InvariantCulture, memberName));
|
||||
|
||||
if (matchingConstructorParameter != null)
|
||||
constructorParameters[matchingConstructorParameter] = CreateObject(reader, matchingConstructorParameter.ParameterType, null);
|
||||
else
|
||||
reader.Skip();
|
||||
|
||||
break;
|
||||
case JsonToken.EndObject:
|
||||
|
||||
@@ -367,7 +367,10 @@ namespace Newtonsoft.Json
|
||||
throw MiscellaneousUtils.CreateArgumentOutOfRangeException("TokenType", reader.TokenType, "Unexpected token type.");
|
||||
}
|
||||
}
|
||||
while (reader.Read() && (currentDepth - 1 < reader.Depth || (currentDepth == reader.Depth && !IsEndToken(reader.TokenType))));
|
||||
while (
|
||||
// stop if we have reached the end of the token being read
|
||||
currentDepth - 1 < reader.Depth - (IsEndToken(reader.TokenType) ? 1 : 0)
|
||||
&& reader.Read());
|
||||
}
|
||||
|
||||
private bool IsEndToken(JsonToken token)
|
||||
|
||||
@@ -348,5 +348,25 @@ namespace Newtonsoft.Json.Utilities
|
||||
writer.Write(h3);
|
||||
writer.Write(h4);
|
||||
}
|
||||
|
||||
public static TSource ForgivingCaseSensitiveFind<TSource>(this IEnumerable<TSource> source, Func<TSource, string> valueSelector, string testValue)
|
||||
{
|
||||
if (source == null)
|
||||
throw new ArgumentNullException("source");
|
||||
if (valueSelector == null)
|
||||
throw new ArgumentNullException("valueSelector");
|
||||
|
||||
var caseInsensitiveResults = source.Where(s => string.Compare(valueSelector(s), testValue, StringComparison.OrdinalIgnoreCase) == 0);
|
||||
if (caseInsensitiveResults.Count() <= 1)
|
||||
{
|
||||
return caseInsensitiveResults.SingleOrDefault();
|
||||
}
|
||||
else
|
||||
{
|
||||
// multiple results returned. now filter using case sensitivity
|
||||
var caseSensitiveResults = source.Where(s => string.Compare(valueSelector(s), testValue, StringComparison.Ordinal) == 0);
|
||||
return caseSensitiveResults.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user