CreateWrapper() private method

private CreateWrapper ( object list ) : IWrappedCollection
list object
return IWrappedCollection
Example #1
0
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContainerContract collectionContract, JsonContract collectionValueContract)
        {
            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            JsonConverter converter;

            if ((((converter = (member != null) ? member.Converter : null) != null) ||
                 ((converter = (collectionContract != null) ? collectionContract.ItemConverter : null) != null) ||
                 ((converter = valueContract.Converter) != null) ||
                 ((converter = Serializer.GetMatchingConverter(valueContract.UnderlyingType)) != null) ||
                 ((converter = valueContract.InternalConverter) != null)) &&
                converter.CanWrite)
            {
                SerializeConvertable(writer, converter, value, valueContract, collectionContract, collectionValueContract);
                return;
            }

            switch (valueContract.ContractType)
            {
            case JsonContractType.Object:
                SerializeObject(writer, value, (JsonObjectContract)valueContract, member, collectionContract, collectionValueContract);
                break;

            case JsonContractType.Array:
                JsonArrayContract arrayContract = (JsonArrayContract)valueContract;
                SerializeList(writer, arrayContract.CreateWrapper(value), arrayContract, member, collectionContract, collectionValueContract);
                break;

            case JsonContractType.Primitive:
                SerializePrimitive(writer, value, (JsonPrimitiveContract)valueContract, member, collectionContract, collectionValueContract);
                break;

            case JsonContractType.String:
                SerializeString(writer, value, (JsonStringContract)valueContract);
                break;

            case JsonContractType.Dictionary:
                JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)valueContract;
                SerializeDictionary(writer, dictionaryContract.CreateWrapper(value), dictionaryContract, member, collectionContract, collectionValueContract);
                break;

#if !(NET35 || NET20 || WINDOWS_PHONE || PORTABLE)
            case JsonContractType.Dynamic:
                SerializeDynamic(writer, (IDynamicMetaObjectProvider)value, (JsonDynamicContract)valueContract, member, collectionContract, collectionValueContract);
                break;
#endif
#if !(SILVERLIGHT || NETFX_CORE || PORTABLE)
            case JsonContractType.Serializable:
                SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract, member, collectionContract, collectionValueContract);
                break;
#endif
            case JsonContractType.Linq:
                ((JToken)value).WriteTo(writer, (Serializer.Converters != null) ? Serializer.Converters.ToArray() : null);
                break;
            }
        }
Example #2
0
 private object CreateAndPopulateList(JsonReader reader, string reference, JsonArrayContract contract)
 {
     return(CollectionUtils.CreateAndPopulateList(contract.CreatedType, delegate(IList l, bool isTemporaryListReference)
     {
         if (reference != null && isTemporaryListReference)
         {
             throw new JsonSerializationException("Cannot preserve reference to array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
         }
         if (contract.OnSerializing != null && isTemporaryListReference)
         {
             throw new JsonSerializationException("Cannot call OnSerializing on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
         }
         if (contract.OnError != null && isTemporaryListReference)
         {
             throw new JsonSerializationException("Cannot call OnError on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
         }
         if (!contract.IsMultidimensionalArray)
         {
             PopulateList(contract.CreateWrapper(l), reader, reference, contract);
         }
         else
         {
             PopulateMultidimensionalArray(l, reader, reference, contract);
         }
     }));
 }
Example #3
0
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerProperty)
        {
            if (value == null)
            {
                writer.WriteNull();
            }
            else
            {
                JsonConverter converter;
                if (((converter = member != null ? member.Converter : (JsonConverter)null) != null || (converter = containerProperty != null ? containerProperty.ItemConverter : (JsonConverter)null) != null || ((converter = containerContract != null ? containerContract.ItemConverter : (JsonConverter)null) != null || (converter = valueContract.Converter) != null || ((converter = this.Serializer.GetMatchingConverter(valueContract.UnderlyingType)) != null || (converter = valueContract.InternalConverter) != null))) && converter.CanWrite)
                {
                    this.SerializeConvertable(writer, converter, value, valueContract, containerContract, containerProperty);
                }
                else
                {
                    switch (valueContract.ContractType)
                    {
                    case JsonContractType.Object:
                        this.SerializeObject(writer, value, (JsonObjectContract)valueContract, member, containerContract, containerProperty);
                        break;

                    case JsonContractType.Array:
                        JsonArrayContract contract1 = (JsonArrayContract)valueContract;
                        if (!contract1.IsMultidimensionalArray)
                        {
                            this.SerializeList(writer, contract1.CreateWrapper(value), contract1, member, containerContract, containerProperty);
                            break;
                        }
                        else
                        {
                            this.SerializeMultidimensionalArray(writer, (Array)value, contract1, member, containerContract, containerProperty);
                            break;
                        }

                    case JsonContractType.Primitive:
                        this.SerializePrimitive(writer, value, (JsonPrimitiveContract)valueContract, member, containerContract, containerProperty);
                        break;

                    case JsonContractType.String:
                        this.SerializeString(writer, value, (JsonStringContract)valueContract);
                        break;

                    case JsonContractType.Dictionary:
                        JsonDictionaryContract contract2 = (JsonDictionaryContract)valueContract;
                        this.SerializeDictionary(writer, contract2.CreateWrapper(value), contract2, member, containerContract, containerProperty);
                        break;

                    case JsonContractType.Serializable:
                        this.SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract, member, containerContract, containerProperty);
                        break;

                    case JsonContractType.Linq:
                        ((JToken)value).WriteTo(writer, this.Serializer.Converters != null ? Enumerable.ToArray <JsonConverter>((IEnumerable <JsonConverter>) this.Serializer.Converters) : (JsonConverter[])null);
                        break;
                    }
                }
            }
        }
Example #4
0
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
        {
            JsonConverter converter = (member != null) ? member.Converter : null;

            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            if ((converter != null ||
                 ((converter = valueContract.Converter) != null) ||
                 ((converter = Serializer.GetMatchingConverter(valueContract.UnderlyingType)) != null) ||
                 ((converter = valueContract.InternalConverter) != null)) &&
                converter.CanWrite)
            {
                SerializeConvertable(writer, converter, value, valueContract);
            }
            else if (valueContract is JsonPrimitiveContract)
            {
                SerializePrimitive(writer, value, (JsonPrimitiveContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonStringContract)
            {
                SerializeString(writer, value, (JsonStringContract)valueContract);
            }
            else if (valueContract is JsonObjectContract)
            {
                SerializeObject(writer, value, (JsonObjectContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonDictionaryContract)
            {
                JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)valueContract;
                SerializeDictionary(writer, dictionaryContract.CreateWrapper(value), dictionaryContract, member, collectionValueContract);
            }
            else if (valueContract is JsonArrayContract)
            {
                JsonArrayContract arrayContract = (JsonArrayContract)valueContract;
                if (!arrayContract.IsMultidimensionalArray)
                {
                    SerializeList(writer, arrayContract.CreateWrapper(value), arrayContract, member, collectionValueContract);
                }
                else
                {
                    SerializeMultidimensionalArray(writer, (Array)value, arrayContract, member, collectionValueContract);
                }
            }
            else if (valueContract is JsonLinqContract)
            {
                ((JToken)value).WriteTo(writer, (Serializer.Converters != null) ? Serializer.Converters.ToArray() : null);
            }
#if !((UNITY_WINRT && !UNITY_EDITOR) || (UNITY_WP8 || UNITY_WP_8_1))
            else if (valueContract is JsonISerializableContract)
            {
                SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract);
            }
#endif
        }
Example #5
0
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
        {
            JsonConverter converter = (member != null) ? member.Converter : null;

            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            if ((converter != null ||
                 ((converter = valueContract.Converter) != null) ||
                 ((converter = Serializer.GetMatchingConverter(valueContract.UnderlyingType)) != null) ||
                 ((converter = valueContract.InternalConverter) != null)) &&
                converter.CanWrite)
            {
                SerializeConvertable(writer, converter, value, valueContract);
            }
            else if (valueContract is JsonPrimitiveContract)
            {
                writer.WriteValue(value);
            }
            else if (valueContract is JsonStringContract)
            {
                SerializeString(writer, value, (JsonStringContract)valueContract);
            }
            else if (valueContract is JsonObjectContract)
            {
                SerializeObject(writer, value, (JsonObjectContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonDictionaryContract)
            {
                JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)valueContract;
                SerializeDictionary(writer, dictionaryContract.CreateWrapper(value), dictionaryContract, member, collectionValueContract);
            }
            else if (valueContract is JsonArrayContract)
            {
                JsonArrayContract arrayContract = (JsonArrayContract)valueContract;
                SerializeList(writer, arrayContract.CreateWrapper(value), arrayContract, member, collectionValueContract);
            }
            else if (valueContract is JsonLinqContract)
            {
                ((JToken)value).WriteTo(writer, (Serializer.Converters != null) ? Serializer.Converters.ToArray() : null);
            }
#if !SILVERLIGHT && !PocketPC
            else if (valueContract is JsonISerializableContract)
            {
                SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract);
            }
#endif
#if !(NET35 || NET20 || WINDOWS_PHONE)
            else if (valueContract is JsonDynamicContract)
            {
                SerializeDynamic(writer, (IDynamicMetaObjectProvider)value, (JsonDynamicContract)valueContract);
            }
#endif
        }
Example #6
0
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
        {
            JsonConverter converter = (member != null) ? member.Converter : null;

            if (converter == null && JsonSerializerSettings.DefaultEnumSerializationHandling == EnumSerializationHandling.Name && value is Enum)
            {
                converter = new StringEnumConverter();
            }

            if (value == null)
            {
                writer.WriteNull();
                return;
            }

            if ((converter != null ||
                 ((converter = valueContract.Converter) != null) ||
                 ((converter = Serializer.GetMatchingConverter(valueContract.UnderlyingType)) != null) ||
                 ((converter = valueContract.InternalConverter) != null)) &&
                converter.CanWrite)
            {
                SerializeConvertable(writer, converter, value, valueContract);
            }
            else if (valueContract is JsonPrimitiveContract)
            {
                SerializePrimitive(writer, value, (JsonPrimitiveContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonStringContract)
            {
                SerializeString(writer, value, (JsonStringContract)valueContract);
            }
            else if (valueContract is JsonObjectContract)
            {
                SerializeObject(writer, value, (JsonObjectContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonDictionaryContract)
            {
                JsonDictionaryContract dictionaryContract = (JsonDictionaryContract)valueContract;
                SerializeDictionary(writer, dictionaryContract.CreateWrapper(value), dictionaryContract, member, collectionValueContract);
            }
            else if (valueContract is JsonArrayContract)
            {
                JsonArrayContract arrayContract = (JsonArrayContract)valueContract;
                SerializeList(writer, arrayContract.CreateWrapper(value), arrayContract, member, collectionValueContract);
            }
            else if (valueContract is JsonLinqContract)
            {
                ((JToken)value).WriteTo(writer, (Serializer.Converters != null) ? Serializer.Converters.ToArray() : null);
            }
            else if (valueContract is JsonISerializableContract)
            {
                SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract);
            }
        }
Example #7
0
 private object CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, object existingValue, string reference)
 {
     if (HasDefinedType(objectType))
     {
         JsonArrayContract jsonArrayContract = EnsureArrayContract(objectType, contract);
         if (existingValue == null || objectType == typeof(BitArray))
         {
             return(CreateAndPopulateList(reader, reference, jsonArrayContract));
         }
         return(PopulateList(jsonArrayContract.CreateWrapper(existingValue), reader, reference, jsonArrayContract));
     }
     return(CreateJToken(reader, contract));
 }
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
        {
            JsonConverter jsonConverter = (member == null) ? null : member.Converter;

            if (value == null)
            {
                writer.WriteNull();
                return;
            }
            if ((jsonConverter != null || (jsonConverter = valueContract.Converter) != null || (jsonConverter = base.Serializer.GetMatchingConverter(valueContract.UnderlyingType)) != null || (jsonConverter = valueContract.InternalConverter) != null) && jsonConverter.CanWrite)
            {
                this.SerializeConvertable(writer, jsonConverter, value, valueContract);
            }
            else if (valueContract is JsonPrimitiveContract)
            {
                this.SerializePrimitive(writer, value, (JsonPrimitiveContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonStringContract)
            {
                this.SerializeString(writer, value, (JsonStringContract)valueContract);
            }
            else if (valueContract is JsonObjectContract)
            {
                this.SerializeObject(writer, value, (JsonObjectContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonDictionaryContract)
            {
                JsonDictionaryContract jsonDictionaryContract = (JsonDictionaryContract)valueContract;
                this.SerializeDictionary(writer, jsonDictionaryContract.CreateWrapper(value), jsonDictionaryContract, member, collectionValueContract);
            }
            else if (valueContract is JsonArrayContract)
            {
                JsonArrayContract jsonArrayContract = (JsonArrayContract)valueContract;
                if (!jsonArrayContract.IsMultidimensionalArray)
                {
                    this.SerializeList(writer, jsonArrayContract.CreateWrapper(value), jsonArrayContract, member, collectionValueContract);
                }
                else
                {
                    this.SerializeMultidimensionalArray(writer, (Array)value, jsonArrayContract, member, collectionValueContract);
                }
            }
            else if (valueContract is JsonLinqContract)
            {
                ((JToken)value).WriteTo(writer, (base.Serializer.Converters == null) ? null : base.Serializer.Converters.ToArray <JsonConverter>());
            }
            else if (valueContract is JsonISerializableContract)
            {
                this.SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract);
            }
        }
Example #9
0
        private object CreateAndPopulateList(JsonReader reader, string reference, JsonArrayContract contract)
        {
            return(CollectionUtils.CreateAndPopulateList(contract.CreatedType, (l, isTemporaryListReference) =>
            {
                if (reference != null && isTemporaryListReference)
                {
                    throw new JsonSerializationException("Cannot preserve reference to array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
                }

#if !PocketPC
                if (contract.OnSerializing != null && isTemporaryListReference)
                {
                    throw new JsonSerializationException("Cannot call OnSerializing on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
                }
#endif
                if (contract.OnError != null && isTemporaryListReference)
                {
                    throw new JsonSerializationException("Cannot call OnError on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
                }

                PopulateList(contract.CreateWrapper(l), reader, reference, contract);
            }));
        }
Example #10
0
        private object CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, object existingValue, string reference)
        {
            object value;

            if (HasDefinedType(objectType))
            {
                JsonArrayContract arrayContract = EnsureArrayContract(objectType, contract);

                if (existingValue == null)
                {
                    value = CreateAndPopulateList(reader, reference, arrayContract);
                }
                else
                {
                    value = PopulateList(arrayContract.CreateWrapper(existingValue), reader, reference, arrayContract);
                }
            }
            else
            {
                value = CreateJToken(reader, contract);
            }
            return(value);
        }
        private void SerializeValue(JsonWriter writer, object value, JsonContract valueContract, JsonProperty member, JsonContract collectionValueContract)
        {
            JsonConverter converter;

            JsonConverter[] array;
            if (member == null)
            {
                converter = null;
            }
            else
            {
                converter = member.Converter;
            }
            JsonConverter jsonConverter = converter;

            if (value == null)
            {
                writer.WriteNull();
                return;
            }
            if (jsonConverter == null)
            {
                JsonConverter converter1 = valueContract.Converter;
                jsonConverter = converter1;
                if (converter1 == null)
                {
                    JsonConverter matchingConverter = base.Serializer.GetMatchingConverter(valueContract.UnderlyingType);
                    jsonConverter = matchingConverter;
                    if (matchingConverter == null)
                    {
                        JsonConverter internalConverter = valueContract.InternalConverter;
                        jsonConverter = internalConverter;
                        if (internalConverter == null)
                        {
                            goto Label0;
                        }
                    }
                }
            }
            if (jsonConverter.CanWrite)
            {
                this.SerializeConvertable(writer, jsonConverter, value, valueContract);
                return;
            }
            if (valueContract is JsonPrimitiveContract)
            {
                this.SerializePrimitive(writer, value, (JsonPrimitiveContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonStringContract)
            {
                this.SerializeString(writer, value, (JsonStringContract)valueContract);
            }
            else if (valueContract is JsonObjectContract)
            {
                this.SerializeObject(writer, value, (JsonObjectContract)valueContract, member, collectionValueContract);
            }
            else if (valueContract is JsonDictionaryContract)
            {
                JsonDictionaryContract jsonDictionaryContract = (JsonDictionaryContract)valueContract;
                this.SerializeDictionary(writer, jsonDictionaryContract.CreateWrapper(value), jsonDictionaryContract, member, collectionValueContract);
            }
            else if (valueContract is JsonArrayContract)
            {
                JsonArrayContract jsonArrayContract = (JsonArrayContract)valueContract;
                if (jsonArrayContract.IsMultidimensionalArray)
                {
                    this.SerializeMultidimensionalArray(writer, (Array)value, jsonArrayContract, member, collectionValueContract);
                }
                else
                {
                    this.SerializeList(writer, jsonArrayContract.CreateWrapper(value), jsonArrayContract, member, collectionValueContract);
                }
            }
            else if (valueContract is JsonLinqContract)
            {
                JToken     jTokens    = (JToken)value;
                JsonWriter jsonWriter = writer;
                if (base.Serializer.Converters == null)
                {
                    array = null;
                }
                else
                {
                    array = base.Serializer.Converters.ToArray <JsonConverter>();
                }
                jTokens.WriteTo(jsonWriter, array);
            }
            else if (valueContract is JsonISerializableContract)
            {
                this.SerializeISerializable(writer, (ISerializable)value, (JsonISerializableContract)valueContract);
            }
        }
		private object CreateAndPopulateList(JsonReader reader, string reference, JsonArrayContract contract)
		{
			return CollectionUtils.CreateAndPopulateList(contract.CreatedType, (l, isTemporaryListReference) =>
			{
				if (reference != null && isTemporaryListReference)
					throw new JsonSerializationException("Cannot preserve reference to array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
				if (contract.OnSerializing != null && isTemporaryListReference)
					throw new JsonSerializationException("Cannot call OnSerializing on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
				if (contract.OnError != null && isTemporaryListReference)
					throw new JsonSerializationException("Cannot call OnError on an array or readonly list: {0}".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

				if (!contract.IsMultidimensionalArray)
					PopulateList(contract.CreateWrapper(l), reader, reference, contract);
				else
					PopulateMultidimensionalArray(l, reader, reference, contract);
			});
		}
 // Token: 0x06000BCD RID: 3021
 // RVA: 0x00044C00 File Offset: 0x00042E00
 private IList CreateNewList(JsonReader reader, JsonArrayContract contract, out bool createdFromNonDefaultCreator)
 {
     if (!contract.CanDeserialize)
     {
         throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Cannot create and populate list type {0}.", CultureInfo.InvariantCulture, contract.CreatedType));
     }
     if (contract.IsReadOnlyOrFixedSize)
     {
         createdFromNonDefaultCreator = true;
         IList list = contract.CreateTemporaryCollection();
         if (contract.ShouldCreateWrapper)
         {
             list = contract.CreateWrapper(list);
         }
         return list;
     }
     if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || this.Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
     {
         object obj = contract.DefaultCreator();
         if (contract.ShouldCreateWrapper)
         {
             obj = contract.CreateWrapper(obj);
         }
         createdFromNonDefaultCreator = false;
         return (IList)obj;
     }
     if (contract.HasParametrizedCreator)
     {
         createdFromNonDefaultCreator = true;
         return contract.CreateTemporaryCollection();
     }
     if (!contract.IsInstantiable)
     {
         throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Could not create an instance of type {0}. Type is an interface or abstract class and cannot be instantiated.", CultureInfo.InvariantCulture, contract.UnderlyingType));
     }
     throw JsonSerializationException.Create(reader, StringUtils.FormatWith("Unable to find a constructor to use for type {0}.", CultureInfo.InvariantCulture, contract.UnderlyingType));
 }
Example #14
0
        private object CreateObjectFromNonDefaultConstructor(JsonReader reader, JsonObjectContract contract, ConstructorInfo constructorInfo, string id)
        {
            ValidationUtils.ArgumentNotNull(constructorInfo, "constructorInfo");
            Type underlyingType = contract.UnderlyingType;
            IDictionary <JsonProperty, object>  dictionary  = ResolvePropertyAndConstructorValues(contract, reader, underlyingType);
            IDictionary <ParameterInfo, object> dictionary2 = ((IEnumerable <ParameterInfo>)constructorInfo.GetParameters()).ToDictionary((Func <ParameterInfo, ParameterInfo>)((ParameterInfo p) => p), (Func <ParameterInfo, object>)((ParameterInfo p) => null));
            IDictionary <JsonProperty, object>  dictionary3 = new Dictionary <JsonProperty, object>();

            foreach (KeyValuePair <JsonProperty, object> item in dictionary)
            {
                ParameterInfo key = dictionary2.ForgivingCaseSensitiveFind((KeyValuePair <ParameterInfo, object> kv) => kv.Key.Name, item.Key.UnderlyingName).Key;
                if (key != null)
                {
                    dictionary2[key] = item.Value;
                }
                else
                {
                    dictionary3.Add(item);
                }
            }
            object obj = constructorInfo.Invoke(dictionary2.Values.ToArray());

            if (id != null)
            {
                base.Serializer.ReferenceResolver.AddReference(this, id, obj);
            }
            contract.InvokeOnDeserializing(obj, base.Serializer.Context);
            foreach (KeyValuePair <JsonProperty, object> item2 in dictionary3)
            {
                JsonProperty key2  = item2.Key;
                object       value = item2.Value;
                if (ShouldSetPropertyValue(item2.Key, item2.Value))
                {
                    key2.ValueProvider.SetValue(obj, value);
                }
                else
                {
                    if (key2.Writable || value == null)
                    {
                        continue;
                    }
                    JsonContract jsonContract = base.Serializer.ContractResolver.ResolveContract(key2.PropertyType);
                    if (jsonContract is JsonArrayContract)
                    {
                        JsonArrayContract jsonArrayContract = jsonContract as JsonArrayContract;
                        object            value2            = key2.ValueProvider.GetValue(obj);
                        if (value2 == null)
                        {
                            continue;
                        }
                        IWrappedCollection wrappedCollection  = jsonArrayContract.CreateWrapper(value2);
                        IWrappedCollection wrappedCollection2 = jsonArrayContract.CreateWrapper(value);
                        foreach (object item3 in wrappedCollection2)
                        {
                            wrappedCollection.Add(item3);
                        }
                    }
                    else
                    {
                        if (!(jsonContract is JsonDictionaryContract))
                        {
                            continue;
                        }
                        JsonDictionaryContract jsonDictionaryContract = jsonContract as JsonDictionaryContract;
                        object value3 = key2.ValueProvider.GetValue(obj);
                        if (value3 == null)
                        {
                            continue;
                        }
                        IWrappedDictionary wrappedDictionary  = jsonDictionaryContract.CreateWrapper(value3);
                        IWrappedDictionary wrappedDictionary2 = jsonDictionaryContract.CreateWrapper(value);
                        foreach (DictionaryEntry item4 in wrappedDictionary2)
                        {
                            wrappedDictionary.Add(item4.Key, item4.Value);
                        }
                    }
                }
            }
            contract.InvokeOnDeserialized(obj, base.Serializer.Context);
            return(obj);
        }
        private IList CreateNewList(JsonReader reader, JsonArrayContract contract, out bool createdFromNonDefaultConstructor)
        {
            // some types like non-generic IEnumerable can be serialized but not deserialized
              if (!contract.CanDeserialize)
            throw JsonSerializationException.Create(reader, "Cannot create and populate list type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.CreatedType));

              if (contract.IsReadOnlyOrFixedSize)
              {
            createdFromNonDefaultConstructor = true;
            IList list = contract.CreateTemporaryCollection();

            if (contract.ShouldCreateWrapper)
              list = contract.CreateWrapper(list);

            return list;
              }
              else if (contract.DefaultCreator != null && (!contract.DefaultCreatorNonPublic || Serializer._constructorHandling == ConstructorHandling.AllowNonPublicDefaultConstructor))
              {
            object list = contract.DefaultCreator();

            if (contract.ShouldCreateWrapper)
              list = contract.CreateWrapper(list);

            createdFromNonDefaultConstructor = false;
            return (IList)list;
              }
              else if (contract.ParametrizedConstructor != null)
              {
            createdFromNonDefaultConstructor = true;
            return contract.CreateTemporaryCollection();
              }
              else
              {
            throw JsonSerializationException.Create(reader, "Unable to find a constructor to use for type {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
              }
        }
    private object CreateAndPopulateList(JsonReader reader, string reference, JsonArrayContract contract)
    {
      return CollectionUtils.CreateAndPopulateList(contract.CreatedType, (l, isTemporaryListReference) =>
        {
          if (reference != null && isTemporaryListReference)
            throw CreateSerializationException(reader, "Cannot preserve reference to array or readonly list: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

#if !PocketPC
          if (contract.OnSerializing != null && isTemporaryListReference)
            throw CreateSerializationException(reader, "Cannot call OnSerializing on an array or readonly list: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));
#endif
          if (contract.OnError != null && isTemporaryListReference)
            throw CreateSerializationException(reader, "Cannot call OnError on an array or readonly list: {0}.".FormatWith(CultureInfo.InvariantCulture, contract.UnderlyingType));

          PopulateList(contract.CreateWrapper(l), reader, reference, contract);
        });
    }
        private object CreateObjectFromNonDefaultConstructor(JsonReader reader, JsonObjectContract contract, ConstructorInfo constructorInfo, string id)
        {
            ValidationUtils.ArgumentNotNull(constructorInfo, "constructorInfo");
            Type underlyingType = contract.UnderlyingType;
            IDictionary <JsonProperty, object>  dictionary  = ResolvePropertyAndConstructorValues(contract, reader, underlyingType);
            IDictionary <ParameterInfo, object> dictionary2 = ((IEnumerable <ParameterInfo>)constructorInfo.GetParameters()).ToDictionary((Func <ParameterInfo, ParameterInfo>)((ParameterInfo p) => p), (Func <ParameterInfo, object>)((ParameterInfo p) => null));
            IDictionary <JsonProperty, object>  dictionary3 = new Dictionary <JsonProperty, object>();

            foreach (KeyValuePair <JsonProperty, object> item in dictionary)
            {
                ParameterInfo key = dictionary2.ForgivingCaseSensitiveFind((KeyValuePair <ParameterInfo, object> kv) => kv.Key.Name, item.Key.UnderlyingName).Key;
                if (key != null)
                {
                    dictionary2[key] = item.Value;
                }
                else
                {
                    dictionary3.Add(item);
                }
            }
            object obj = constructorInfo.Invoke(dictionary2.Values.ToArray());

            if (id != null)
            {
                base.Serializer.ReferenceResolver.AddReference(this, id, obj);
            }
            contract.InvokeOnDeserializing(obj, base.Serializer.Context);
            foreach (KeyValuePair <JsonProperty, object> item2 in dictionary3)
            {
                JsonProperty key2  = item2.Key;
                object       value = item2.Value;
                if (ShouldSetPropertyValue(item2.Key, item2.Value))
                {
                    key2.ValueProvider.SetValue(obj, value);
                }
                else if (!key2.Writable && value != null)
                {
                    JsonContract jsonContract = base.Serializer.ContractResolver.ResolveContract(key2.PropertyType);
                    if (jsonContract is JsonArrayContract)
                    {
                        JsonArrayContract jsonArrayContract = jsonContract as JsonArrayContract;
                        object            value2            = key2.ValueProvider.GetValue(obj);
                        if (value2 != null)
                        {
                            IWrappedCollection wrappedCollection  = jsonArrayContract.CreateWrapper(value2);
                            IWrappedCollection wrappedCollection2 = jsonArrayContract.CreateWrapper(value);
                            IEnumerator        enumerator3        = wrappedCollection2.GetEnumerator();
                            try
                            {
                                while (enumerator3.MoveNext())
                                {
                                    object current3 = enumerator3.Current;
                                    wrappedCollection.Add(current3);
                                }
                            }
                            finally
                            {
                                IDisposable disposable;
                                if ((disposable = (enumerator3 as IDisposable)) != null)
                                {
                                    disposable.Dispose();
                                }
                            }
                        }
                    }
                    else if (jsonContract is JsonDictionaryContract)
                    {
                        JsonDictionaryContract jsonDictionaryContract = jsonContract as JsonDictionaryContract;
                        object value3 = key2.ValueProvider.GetValue(obj);
                        if (value3 != null)
                        {
                            IWrappedDictionary    wrappedDictionary  = jsonDictionaryContract.CreateWrapper(value3);
                            IWrappedDictionary    wrappedDictionary2 = jsonDictionaryContract.CreateWrapper(value);
                            IDictionaryEnumerator enumerator4        = wrappedDictionary2.GetEnumerator();
                            try
                            {
                                while (enumerator4.MoveNext())
                                {
                                    DictionaryEntry dictionaryEntry = (DictionaryEntry)enumerator4.Current;
                                    wrappedDictionary.Add(dictionaryEntry.Key, dictionaryEntry.Value);
                                }
                            }
                            finally
                            {
                                IDisposable disposable2;
                                if ((disposable2 = (enumerator4 as IDisposable)) != null)
                                {
                                    disposable2.Dispose();
                                }
                            }
                        }
                    }
                }
            }
            contract.InvokeOnDeserialized(obj, base.Serializer.Context);
            return(obj);
        }