Code Coverage Statistics for Source File
Newtonsoft.Json\JsonPropertyAttribute.cs
Symbol Coverage: 86.21% (25 of 29)
Branch Coverage: 80.00% (24 of 30)
Cyclomatic Complexity Avg: 1.33 Max:2
Code Lines: 17
Symbol Coverage Trend
View:
L | V | Source |
---|---|---|
1 |
using System; |
|
2 |
||
3 |
namespace Newtonsoft.Json |
|
4 |
{ |
|
5 |
/// <summary> |
|
6 |
/// Instructs the <see cref="JsonSerializer"/> to always serialize the member with the specified name. |
|
7 |
/// </summary> |
|
8 |
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)] |
|
9 |
public sealed class JsonPropertyAttribute : Attribute |
|
10 |
{ |
|
11 |
// yuck. can't set nullable properties on an attribute in C# |
|
12 |
// have to use this approach to get an unset default state |
|
13 |
internal NullValueHandling? _nullValueHandling; |
|
14 |
internal DefaultValueHandling? _defaultValueHandling; |
|
15 |
internal ReferenceLoopHandling? _referenceLoopHandling; |
|
16 |
internal ObjectCreationHandling? _objectCreationHandling; |
|
17 |
internal TypeNameHandling? _typeNameHandling; |
|
18 |
internal bool? _isReference; |
|
19 |
||
20 |
/// <summary> |
|
21 |
/// Gets or sets the null value handling used when serializing this property. |
|
22 |
/// </summary> |
|
23 |
/// <value>The null value handling.</value> |
|
24 |
public NullValueHandling NullValueHandling |
|
25 |
{ |
|
26 |
2 |
get { return _nullValueHandling ?? default(NullValueHandling); }
|
27 |
4 |
set { _nullValueHandling = value; }
|
28 |
} |
|
29 |
||
30 |
/// <summary> |
|
31 |
/// Gets or sets the default value handling used when serializing this property. |
|
32 |
/// </summary> |
|
33 |
/// <value>The default value handling.</value> |
|
34 |
public DefaultValueHandling DefaultValueHandling |
|
35 |
{ |
|
36 |
2 |
get { return _defaultValueHandling ?? default(DefaultValueHandling); }
|
37 |
3 |
set { _defaultValueHandling = value; }
|
38 |
} |
|
39 |
||
40 |
/// <summary> |
|
41 |
/// Gets or sets the reference loop handling used when serializing this property. |
|
42 |
/// </summary> |
|
43 |
/// <value>The reference loop handling.</value> |
|
44 |
public ReferenceLoopHandling ReferenceLoopHandling |
|
45 |
{ |
|
46 |
2 |
get { return _referenceLoopHandling ?? default(ReferenceLoopHandling); }
|
47 |
4 |
set { _referenceLoopHandling = value; }
|
48 |
} |
|
49 |
||
50 |
/// <summary> |
|
51 |
/// Gets or sets the object creation handling used when deserializing this property. |
|
52 |
/// </summary> |
|
53 |
/// <value>The object creation handling.</value> |
|
54 |
public ObjectCreationHandling ObjectCreationHandling |
|
55 |
{ |
|
56 |
0 |
get { return _objectCreationHandling ?? default(ObjectCreationHandling); }
|
57 |
2 |
set { _objectCreationHandling = value; }
|
58 |
} |
|
59 |
||
60 |
/// <summary> |
|
61 |
/// Gets or sets the type name handling used when serializing this property. |
|
62 |
/// </summary> |
|
63 |
/// <value>The type name handling.</value> |
|
64 |
public TypeNameHandling TypeNameHandling |
|
65 |
{ |
|
66 |
0 |
get { return _typeNameHandling ?? default(TypeNameHandling); }
|
67 |
1 |
set { _typeNameHandling = value; }
|
68 |
} |
|
69 |
||
70 |
/// <summary> |
|
71 |
/// Gets or sets whether this property's value is serialized as a reference. |
|
72 |
/// </summary> |
|
73 |
/// <value>Whether this property's value is serialized as a reference.</value> |
|
74 |
public bool IsReference |
|
75 |
{ |
|
76 |
3 |
get { return _isReference ?? default(bool); }
|
77 |
2 |
set { _isReference = value; }
|
78 |
} |
|
79 |
||
80 |
/// <summary> |
|
81 |
/// Gets or sets the name of the property. |
|
82 |
/// </summary> |
|
83 |
/// <value>The name of the property.</value> |
|
84 |
public string PropertyName { get; set; } |
|
85 |
||
86 |
/// <summary> |
|
87 |
/// Gets or sets a value indicating whether this property is required. |
|
88 |
/// </summary> |
|
89 |
/// <value> |
|
90 |
/// A value indicating whether this property is required. |
|
91 |
/// </value> |
|
92 |
public Required Required { get; set; } |
|
93 |
||
94 |
/// <summary> |
|
95 |
/// Initializes a new instance of the <see cref="JsonPropertyAttribute"/> class. |
|
96 |
/// </summary> |
|
97 |
76 |
public JsonPropertyAttribute()
|
98 |
{ |
|
99 |
76 |
}
|
100 |
||
101 |
/// <summary> |
|
102 |
/// Initializes a new instance of the <see cref="JsonPropertyAttribute"/> class with the specified name. |
|
103 |
/// </summary> |
|
104 |
/// <param name="propertyName">Name of the property.</param> |
|
105 |
19 |
public JsonPropertyAttribute(string propertyName)
|
106 |
{ |
|
107 |
19 |
PropertyName = propertyName;
|
108 |
19 |
}
|
109 |
} |
|
110 |
} |