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 Newtonsoft.Json.Utilities;
30
using Newtonsoft.Json.Utilities.LinqBridge;
33
namespace Newtonsoft.Json.Serialization
36
/// Maps a JSON property to a .NET member or constructor parameter.
38
public class JsonProperty
40
internal Required? _required;
41
internal bool _hasExplicitDefaultValue;
42
internal object _defaultValue;
44
// use to cache contract during deserialization
45
internal JsonContract PropertyContract { get; set; }
48
/// Gets or sets the name of the property.
50
/// <value>The name of the property.</value>
51
public string PropertyName { get; set; }
54
/// Gets or sets the type that declared this property.
56
/// <value>The type that declared this property.</value>
57
public Type DeclaringType { get; set; }
60
/// Gets or sets the order of serialization and deserialization of a member.
62
/// <value>The numeric order of serialization or deserialization.</value>
63
public int? Order { get; set; }
66
/// Gets or sets the name of the underlying member or parameter.
68
/// <value>The name of the underlying member or parameter.</value>
69
public string UnderlyingName { get; set; }
72
/// Gets the <see cref="IValueProvider"/> that will get and set the <see cref="JsonProperty"/> during serialization.
74
/// <value>The <see cref="IValueProvider"/> that will get and set the <see cref="JsonProperty"/> during serialization.</value>
75
public IValueProvider ValueProvider { get; set; }
78
/// Gets or sets the type of the property.
80
/// <value>The type of the property.</value>
81
public Type PropertyType { get; set; }
84
/// Gets or sets the <see cref="JsonConverter" /> for the property.
85
/// If set this converter takes presidence over the contract converter for the property type.
87
/// <value>The converter.</value>
88
public JsonConverter Converter { get; set; }
91
/// Gets the member converter.
93
/// <value>The member converter.</value>
94
public JsonConverter MemberConverter { get; set; }
97
/// Gets a value indicating whether this <see cref="JsonProperty"/> is ignored.
99
/// <value><c>true</c> if ignored; otherwise, <c>false</c>.</value>
100
public bool Ignored { get; set; }
103
/// Gets a value indicating whether this <see cref="JsonProperty"/> is readable.
105
/// <value><c>true</c> if readable; otherwise, <c>false</c>.</value>
106
public bool Readable { get; set; }
109
/// Gets a value indicating whether this <see cref="JsonProperty"/> is writable.
111
/// <value><c>true</c> if writable; otherwise, <c>false</c>.</value>
112
public bool Writable { get; set; }
115
/// Gets a value indicating whether this <see cref="JsonProperty"/> has a member attribute.
117
/// <value><c>true</c> if has a member attribute; otherwise, <c>false</c>.</value>
118
public bool HasMemberAttribute { get; set; }
121
/// Gets the default value.
123
/// <value>The default value.</value>
124
public object DefaultValue
128
return _defaultValue;
132
_hasExplicitDefaultValue = true;
133
_defaultValue = value;
137
internal object GetResolvedDefaultValue()
139
if (!_hasExplicitDefaultValue && PropertyType != null)
140
return ReflectionUtils.GetDefaultValue(PropertyType);
142
return _defaultValue;
146
/// Gets a value indicating whether this <see cref="JsonProperty"/> is required.
148
/// <value>A value indicating whether this <see cref="JsonProperty"/> is required.</value>
149
public Required Required
151
get { return _required ?? Required.Default; }
152
set { _required = value; }
156
/// Gets a value indicating whether this property preserves object references.
159
/// <c>true</c> if this instance is reference; otherwise, <c>false</c>.
161
public bool? IsReference { get; set; }
164
/// Gets the property null value handling.
166
/// <value>The null value handling.</value>
167
public NullValueHandling? NullValueHandling { get; set; }
170
/// Gets the property default value handling.
172
/// <value>The default value handling.</value>
173
public DefaultValueHandling? DefaultValueHandling { get; set; }
176
/// Gets the property reference loop handling.
178
/// <value>The reference loop handling.</value>
179
public ReferenceLoopHandling? ReferenceLoopHandling { get; set; }
182
/// Gets the property object creation handling.
184
/// <value>The object creation handling.</value>
185
public ObjectCreationHandling? ObjectCreationHandling { get; set; }
188
/// Gets or sets the type name handling.
190
/// <value>The type name handling.</value>
191
public TypeNameHandling? TypeNameHandling { get; set; }
194
/// Gets or sets a predicate used to determine whether the property should be serialize.
196
/// <value>A predicate used to determine whether the property should be serialize.</value>
197
public Predicate<object> ShouldSerialize { get; set; }
200
/// Gets or sets a predicate used to determine whether the property should be serialized.
202
/// <value>A predicate used to determine whether the property should be serialized.</value>
203
public Predicate<object> GetIsSpecified { get; set; }
206
/// Gets or sets an action used to set whether the property has been deserialized.
208
/// <value>An action used to set whether the property has been deserialized.</value>
209
public Action<object, object> SetIsSpecified { get; set; }
212
/// Returns a <see cref="String"/> that represents this instance.
215
/// A <see cref="String"/> that represents this instance.
217
public override string ToString()
223
/// Gets or sets the converter used when serializing the property's collection items.
225
/// <value>The collection's items converter.</value>
226
public JsonConverter ItemConverter { get; set; }
229
/// Gets or sets whether this property's collection items are serialized as a reference.
231
/// <value>Whether this property's collection items are serialized as a reference.</value>
232
public bool? ItemIsReference { get; set; }
235
/// Gets or sets the the type name handling used when serializing the property's collection items.
237
/// <value>The collection's items type name handling.</value>
238
public TypeNameHandling? ItemTypeNameHandling { get; set; }
241
/// Gets or sets the the reference loop handling used when serializing the property's collection items.
243
/// <value>The collection's items reference loop handling.</value>
244
public ReferenceLoopHandling? ItemReferenceLoopHandling { get; set; }
b'\\ No newline at end of file'