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 
28 namespace Newtonsoft.Json
29 {
30   /// <summary>
31   /// Instructs the <see cref="JsonSerializer"/> how to serialize the object.
32   /// </summary>
33   [AttributeUsage(AttributeTargets.Class | AttributeTargets.Interface, AllowMultiple = false)]
34   public abstract class JsonContainerAttribute : Attribute
35   {
36     /// <summary>
37     /// Gets or sets the id.
38     /// </summary>
39     /// <value>The id.</value>
40     public string Id { get; set; }
41     /// <summary>
42     /// Gets or sets the title.
43     /// </summary>
44     /// <value>The title.</value>
45     public string Title { get; set; }
46     /// <summary>
47     /// Gets or sets the description.
48     /// </summary>
49     /// <value>The description.</value>
50     public string Description { get; set; }
51 
52     /// <summary>
53     /// Gets the collection's items converter.
54     /// </summary>
55     /// <value>The collection's items converter.</value>
56     public Type ItemConverterType { get; set; }
57 
58     // yuck. can't set nullable properties on an attribute in C#
59     // have to use this approach to get an unset default state
60     internal bool? _isReference;
61     internal bool? _itemIsReference;
62     internal ReferenceLoopHandling? _itemReferenceLoopHandling;
63     internal TypeNameHandling? _itemTypeNameHandling;
64 
65     /// <summary>
66     /// Gets or sets a value that indicates whether to preserve object references.
67     /// </summary>
68     /// <value>
69     /// 	<c>true</c> to keep object reference; otherwise, <c>false</c>. The default is <c>false</c>.
70     /// </value>
71     public bool IsReference
72     {
73       get { return _isReference ?? default(bool); }
74       set { _isReference = value; }
75     }
76 
77     /// <summary>
78     /// Gets or sets a value that indicates whether to preserve collection's items references.
79     /// </summary>
80     /// <value>
81     /// 	<c>true</c> to keep collection's items object references; otherwise, <c>false</c>. The default is <c>false</c>.
82     /// </value>
83     public bool ItemIsReference
84     {
85       get { return _itemIsReference ?? default(bool); }
86       set { _itemIsReference = value; }
87     }
88 
89     /// <summary>
90     /// Gets or sets the reference loop handling used when serializing the collection's items.
91     /// </summary>
92     /// <value>The reference loop handling.</value>
93     public ReferenceLoopHandling ItemReferenceLoopHandling
94     {
95       get { return _itemReferenceLoopHandling ?? default(ReferenceLoopHandling); }
96       set { _itemReferenceLoopHandling = value; }
97     }
98 
99     /// <summary>
100     /// Gets or sets the type name handling used when serializing the collection's items.
101     /// </summary>
102     /// <value>The type name handling.</value>
103     public TypeNameHandling ItemTypeNameHandling
104     {
105       get { return _itemTypeNameHandling ?? default(TypeNameHandling); }
106       set { _itemTypeNameHandling = value; }
107     }
108 
109     /// <summary>
110     /// Initializes a new instance of the <see cref="JsonContainerAttribute"/> class.
111     /// </summary>
JsonContainerAttribute()112     protected JsonContainerAttribute()
113     {
114     }
115 
116     /// <summary>
117     /// Initializes a new instance of the <see cref="JsonContainerAttribute"/> class with the specified container Id.
118     /// </summary>
119     /// <param name="id">The container Id.</param>
JsonContainerAttribute(string id)120     protected JsonContainerAttribute(string id)
121     {
122       Id = id;
123     }
124   }
125 }