-Fixed creator parameters relying on dictionary implementation for order

This commit is contained in:
James Newton-King
2014-05-08 14:33:28 +12:00
parent 1a6f7cdada
commit cf7a83e91c
2 changed files with 10 additions and 5 deletions
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json.Serialization
assembly = Assembly.LoadWithPartialName(assemblyName); assembly = Assembly.LoadWithPartialName(assemblyName);
#pragma warning restore 618,612 #pragma warning restore 618,612
#elif NETFX_CORE || PORTABLE #elif NETFX_CORE || PORTABLE
assembly = Assembly.Load(new AssemblyName(assemblyName)); assembly = Assembly.Load(new AssemblyName(assemblyName));
#else #else
assembly = Assembly.Load(assemblyName); assembly = Assembly.Load(assemblyName);
#endif #endif
@@ -1588,16 +1588,21 @@ To fix this error either change the environment to be fully trusted, change the
IDictionary<string, object> extensionData; IDictionary<string, object> extensionData;
IDictionary<JsonProperty, object> propertyValues = ResolvePropertyAndCreatorValues(contract, containerProperty, reader, objectType, out extensionData); IDictionary<JsonProperty, object> propertyValues = ResolvePropertyAndCreatorValues(contract, containerProperty, reader, objectType, out extensionData);
IDictionary<JsonProperty, object> creatorParameters = contract.CreatorParameters.ToDictionary(p => p, p => (object)null); object[] creatorParameterValues = new object[contract.CreatorParameters.Count];
IDictionary<JsonProperty, object> remainingPropertyValues = new Dictionary<JsonProperty, object>(); IDictionary<JsonProperty, object> remainingPropertyValues = new Dictionary<JsonProperty, object>();
foreach (KeyValuePair<JsonProperty, object> propertyValue in propertyValues) foreach (KeyValuePair<JsonProperty, object> propertyValue in propertyValues)
{ {
JsonProperty matchingCreatorParameter = creatorParameters.ForgivingCaseSensitiveFind(kv => kv.Key.PropertyName, propertyValue.Key.PropertyName).Key; JsonProperty matchingCreatorParameter = contract.CreatorParameters.ForgivingCaseSensitiveFind(p => p.PropertyName, propertyValue.Key.PropertyName);
if (matchingCreatorParameter != null) if (matchingCreatorParameter != null)
creatorParameters[matchingCreatorParameter] = propertyValue.Value; {
int i = contract.CreatorParameters.IndexOf(matchingCreatorParameter);
creatorParameterValues[i] = propertyValue.Value;
}
else else
{
remainingPropertyValues.Add(propertyValue); remainingPropertyValues.Add(propertyValue);
}
if (propertiesPresence != null) if (propertiesPresence != null)
{ {
@@ -1608,7 +1613,7 @@ To fix this error either change the environment to be fully trusted, change the
} }
} }
object createdObject = creator(creatorParameters.Values.ToArray()); object createdObject = creator(creatorParameterValues);
if (id != null) if (id != null)
AddReference(reader, id, createdObject); AddReference(reader, id, createdObject);