2
// Copyright (c) 2007 James Newton-King
4
// Permission is hereby granted, free of charge, to any person
5
// obtaining a copy of this software and associated documentation
6
// files (the "Software"), to deal in the Software without
7
// restriction, including without limitation the rights to use,
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following
13
// The above copyright notice and this permission notice shall be
14
// included in all copies or substantial portions of the Software.
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
// OTHER DEALINGS IN THE SOFTWARE.
27
using System.Collections.Generic;
28
using System.Reflection;
29
using Newtonsoft.Json.Utilities;
30
using System.Collections;
32
using Newtonsoft.Json.Utilities.LinqBridge;
37
namespace Newtonsoft.Json.Serialization
40
/// Contract details for a <see cref="Type"/> used by the <see cref="JsonSerializer"/>.
42
public class JsonContainerContract : JsonContract
44
private JsonContract _itemContract;
45
private JsonContract _finalItemContract;
47
// will be null for containers that don't have an item type (e.g. IList) or for complex objects
48
internal JsonContract ItemContract
50
get { return _itemContract; }
53
_itemContract = value;
54
if (_itemContract != null)
56
_finalItemContract = (_itemContract.UnderlyingType.IsSealed()) ? _itemContract : null;
60
_finalItemContract = null;
65
// the final (i.e. can't be inherited from like a sealed class or valuetype) item contract
66
internal JsonContract FinalItemContract
68
get { return _finalItemContract; }
72
/// Gets or sets the default collection items <see cref="JsonConverter" />.
74
/// <value>The converter.</value>
75
public JsonConverter ItemConverter { get; set; }
78
/// Gets or sets a value indicating whether the collection items preserve object references.
80
/// <value><c>true</c> if collection items preserve object references; otherwise, <c>false</c>.</value>
81
public bool? ItemIsReference { get; set; }
84
/// Gets or sets the collection item reference loop handling.
86
/// <value>The reference loop handling.</value>
87
public ReferenceLoopHandling? ItemReferenceLoopHandling { get; set; }
90
/// Gets or sets the collection item type name handling.
92
/// <value>The type name handling.</value>
93
public TypeNameHandling? ItemTypeNameHandling { get; set; }
96
/// Initializes a new instance of the <see cref="JsonContainerContract"/> class.
98
/// <param name="underlyingType">The underlying type for the contract.</param>
99
internal JsonContainerContract(Type underlyingType)
100
: base(underlyingType)
102
JsonContainerAttribute jsonContainerAttribute = JsonTypeReflector.GetJsonContainerAttribute(underlyingType);
104
if (jsonContainerAttribute != null)
106
if (jsonContainerAttribute.ItemConverterType != null)
107
ItemConverter = JsonConverterAttribute.CreateJsonConverterInstance(jsonContainerAttribute.ItemConverterType);
109
ItemIsReference = jsonContainerAttribute._itemIsReference;
110
ItemReferenceLoopHandling = jsonContainerAttribute._itemReferenceLoopHandling;
111
ItemTypeNameHandling = jsonContainerAttribute._itemTypeNameHandling;
b'\\ No newline at end of file'