~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/Newtonsoft.Json/Src/Newtonsoft.Json/Serialization/JsonProperty.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region License
 
2
// Copyright (c) 2007 James Newton-King
 
3
//
 
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
 
11
// conditions:
 
12
//
 
13
// The above copyright notice and this permission notice shall be
 
14
// included in all copies or substantial portions of the Software.
 
15
//
 
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.
 
24
#endregion
 
25
 
 
26
using System;
 
27
using Newtonsoft.Json.Utilities;
 
28
 
 
29
#if NET20
 
30
using Newtonsoft.Json.Utilities.LinqBridge;
 
31
#endif
 
32
 
 
33
namespace Newtonsoft.Json.Serialization
 
34
{
 
35
  /// <summary>
 
36
  /// Maps a JSON property to a .NET member or constructor parameter.
 
37
  /// </summary>
 
38
  public class JsonProperty
 
39
  {
 
40
    internal Required? _required;
 
41
    internal bool _hasExplicitDefaultValue;
 
42
    internal object _defaultValue;
 
43
 
 
44
    // use to cache contract during deserialization
 
45
    internal JsonContract PropertyContract { get; set; }
 
46
    
 
47
    /// <summary>
 
48
    /// Gets or sets the name of the property.
 
49
    /// </summary>
 
50
    /// <value>The name of the property.</value>
 
51
    public string PropertyName { get; set; }
 
52
 
 
53
    /// <summary>
 
54
    /// Gets or sets the type that declared this property.
 
55
    /// </summary>
 
56
    /// <value>The type that declared this property.</value>
 
57
    public Type DeclaringType { get; set; }
 
58
 
 
59
    /// <summary>
 
60
    /// Gets or sets the order of serialization and deserialization of a member.
 
61
    /// </summary>
 
62
    /// <value>The numeric order of serialization or deserialization.</value>
 
63
    public int? Order { get; set; }
 
64
 
 
65
    /// <summary>
 
66
    /// Gets or sets the name of the underlying member or parameter.
 
67
    /// </summary>
 
68
    /// <value>The name of the underlying member or parameter.</value>
 
69
    public string UnderlyingName { get; set; }
 
70
 
 
71
    /// <summary>
 
72
    /// Gets the <see cref="IValueProvider"/> that will get and set the <see cref="JsonProperty"/> during serialization.
 
73
    /// </summary>
 
74
    /// <value>The <see cref="IValueProvider"/> that will get and set the <see cref="JsonProperty"/> during serialization.</value>
 
75
    public IValueProvider ValueProvider { get; set; }
 
76
 
 
77
    /// <summary>
 
78
    /// Gets or sets the type of the property.
 
79
    /// </summary>
 
80
    /// <value>The type of the property.</value>
 
81
    public Type PropertyType { get; set; }
 
82
 
 
83
    /// <summary>
 
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.
 
86
    /// </summary>
 
87
    /// <value>The converter.</value>
 
88
    public JsonConverter Converter { get; set; }
 
89
 
 
90
    /// <summary>
 
91
    /// Gets the member converter.
 
92
    /// </summary>
 
93
    /// <value>The member converter.</value>
 
94
    public JsonConverter MemberConverter { get; set; }
 
95
 
 
96
    /// <summary>
 
97
    /// Gets a value indicating whether this <see cref="JsonProperty"/> is ignored.
 
98
    /// </summary>
 
99
    /// <value><c>true</c> if ignored; otherwise, <c>false</c>.</value>
 
100
    public bool Ignored { get; set; }
 
101
 
 
102
    /// <summary>
 
103
    /// Gets a value indicating whether this <see cref="JsonProperty"/> is readable.
 
104
    /// </summary>
 
105
    /// <value><c>true</c> if readable; otherwise, <c>false</c>.</value>
 
106
    public bool Readable { get; set; }
 
107
 
 
108
    /// <summary>
 
109
    /// Gets a value indicating whether this <see cref="JsonProperty"/> is writable.
 
110
    /// </summary>
 
111
    /// <value><c>true</c> if writable; otherwise, <c>false</c>.</value>
 
112
    public bool Writable { get; set; }
 
113
 
 
114
    /// <summary>
 
115
    /// Gets a value indicating whether this <see cref="JsonProperty"/> has a member attribute.
 
116
    /// </summary>
 
117
    /// <value><c>true</c> if has a member attribute; otherwise, <c>false</c>.</value>
 
118
    public bool HasMemberAttribute { get; set; }
 
119
 
 
120
    /// <summary>
 
121
    /// Gets the default value.
 
122
    /// </summary>
 
123
    /// <value>The default value.</value>
 
124
    public object DefaultValue
 
125
    {
 
126
      get
 
127
      {
 
128
        return _defaultValue;
 
129
      }
 
130
      set
 
131
      {
 
132
        _hasExplicitDefaultValue = true;
 
133
        _defaultValue = value;
 
134
      }
 
135
    }
 
136
 
 
137
    internal object GetResolvedDefaultValue()
 
138
    {
 
139
      if (!_hasExplicitDefaultValue && PropertyType != null)
 
140
        return ReflectionUtils.GetDefaultValue(PropertyType);
 
141
 
 
142
      return _defaultValue;
 
143
    }
 
144
 
 
145
    /// <summary>
 
146
    /// Gets a value indicating whether this <see cref="JsonProperty"/> is required.
 
147
    /// </summary>
 
148
    /// <value>A value indicating whether this <see cref="JsonProperty"/> is required.</value>
 
149
    public Required Required
 
150
    {
 
151
      get { return _required ?? Required.Default; }
 
152
      set { _required = value; }
 
153
    }
 
154
 
 
155
    /// <summary>
 
156
    /// Gets a value indicating whether this property preserves object references.
 
157
    /// </summary>
 
158
    /// <value>
 
159
    ///         <c>true</c> if this instance is reference; otherwise, <c>false</c>.
 
160
    /// </value>
 
161
    public bool? IsReference { get; set; }
 
162
 
 
163
    /// <summary>
 
164
    /// Gets the property null value handling.
 
165
    /// </summary>
 
166
    /// <value>The null value handling.</value>
 
167
    public NullValueHandling? NullValueHandling { get; set; }
 
168
 
 
169
    /// <summary>
 
170
    /// Gets the property default value handling.
 
171
    /// </summary>
 
172
    /// <value>The default value handling.</value>
 
173
    public DefaultValueHandling? DefaultValueHandling { get; set; }
 
174
 
 
175
    /// <summary>
 
176
    /// Gets the property reference loop handling.
 
177
    /// </summary>
 
178
    /// <value>The reference loop handling.</value>
 
179
    public ReferenceLoopHandling? ReferenceLoopHandling { get; set; }
 
180
 
 
181
    /// <summary>
 
182
    /// Gets the property object creation handling.
 
183
    /// </summary>
 
184
    /// <value>The object creation handling.</value>
 
185
    public ObjectCreationHandling? ObjectCreationHandling { get; set; }
 
186
 
 
187
    /// <summary>
 
188
    /// Gets or sets the type name handling.
 
189
    /// </summary>
 
190
    /// <value>The type name handling.</value>
 
191
    public TypeNameHandling? TypeNameHandling { get; set; }
 
192
 
 
193
    /// <summary>
 
194
    /// Gets or sets a predicate used to determine whether the property should be serialize.
 
195
    /// </summary>
 
196
    /// <value>A predicate used to determine whether the property should be serialize.</value>
 
197
    public Predicate<object> ShouldSerialize { get; set; }
 
198
 
 
199
    /// <summary>
 
200
    /// Gets or sets a predicate used to determine whether the property should be serialized.
 
201
    /// </summary>
 
202
    /// <value>A predicate used to determine whether the property should be serialized.</value>
 
203
    public Predicate<object> GetIsSpecified { get; set; }
 
204
 
 
205
    /// <summary>
 
206
    /// Gets or sets an action used to set whether the property has been deserialized.
 
207
    /// </summary>
 
208
    /// <value>An action used to set whether the property has been deserialized.</value>
 
209
    public Action<object, object> SetIsSpecified { get; set; }
 
210
 
 
211
    /// <summary>
 
212
    /// Returns a <see cref="String"/> that represents this instance.
 
213
    /// </summary>
 
214
    /// <returns>
 
215
    /// A <see cref="String"/> that represents this instance.
 
216
    /// </returns>
 
217
    public override string ToString()
 
218
    {
 
219
      return PropertyName;
 
220
    }
 
221
 
 
222
    /// <summary>
 
223
    /// Gets or sets the converter used when serializing the property's collection items.
 
224
    /// </summary>
 
225
    /// <value>The collection's items converter.</value>
 
226
    public JsonConverter ItemConverter { get; set; }
 
227
 
 
228
    /// <summary>
 
229
    /// Gets or sets whether this property's collection items are serialized as a reference.
 
230
    /// </summary>
 
231
    /// <value>Whether this property's collection items are serialized as a reference.</value>
 
232
    public bool? ItemIsReference { get; set; }
 
233
 
 
234
    /// <summary>
 
235
    /// Gets or sets the the type name handling used when serializing the property's collection items.
 
236
    /// </summary>
 
237
    /// <value>The collection's items type name handling.</value>
 
238
    public TypeNameHandling? ItemTypeNameHandling { get; set; }
 
239
 
 
240
    /// <summary>
 
241
    /// Gets or sets the the reference loop handling used when serializing the property's collection items.
 
242
    /// </summary>
 
243
    /// <value>The collection's items reference loop handling.</value>
 
244
    public ReferenceLoopHandling? ItemReferenceLoopHandling { get; set; }
 
245
  }
 
246
}
 
 
b'\\ No newline at end of file'