Skip to content

Commit 873a23a

Browse files
committed
-XML documentation
1 parent 1b6fe85 commit 873a23a

File tree

11 files changed

+169
-47
lines changed

11 files changed

+169
-47
lines changed

Src/Newtonsoft.Json.Tests/Bson/BsonReaderTests.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ namespace Newtonsoft.Json.Tests.Bson
3838
{
3939
public class BsonReaderTests : TestFixtureBase
4040
{
41-
private char pound = '\u00a3';
42-
private char euro = '\u20ac';
41+
private const char Euro = '\u20ac';
4342

4443
[Test]
4544
public void ReadSingleObject()
@@ -829,7 +828,7 @@ public void TestReadLenStringValueShortTripleByte()
829828
//sb.Append('1',127); //first char of euro at the end of the boundry.
830829
//sb.Append(euro, 5);
831830
//sb.Append('1',128);
832-
sb.Append(euro);
831+
sb.Append(Euro);
833832

834833
string expected = sb.ToString();
835834
Assert.AreEqual(expected, WriteAndReadStringValue(expected));
@@ -840,9 +839,9 @@ public void TestReadLenStringValueTripleByteCharBufferBoundry0()
840839
{
841840
StringBuilder sb = new StringBuilder();
842841
sb.Append('1', 127); //first char of euro at the end of the boundry.
843-
sb.Append(euro, 5);
842+
sb.Append(Euro, 5);
844843
sb.Append('1', 128);
845-
sb.Append(euro);
844+
sb.Append(Euro);
846845

847846
string expected = sb.ToString();
848847
Assert.AreEqual(expected, WriteAndReadStringValue(expected));
@@ -853,9 +852,9 @@ public void TestReadLenStringValueTripleByteCharBufferBoundry1()
853852
{
854853
StringBuilder sb = new StringBuilder();
855854
sb.Append('1', 126);
856-
sb.Append(euro, 5); //middle char of euro at the end of the boundry.
855+
sb.Append(Euro, 5); //middle char of euro at the end of the boundry.
857856
sb.Append('1', 128);
858-
sb.Append(euro);
857+
sb.Append(Euro);
859858

860859
string expected = sb.ToString();
861860
string result = WriteAndReadStringValue(expected);
@@ -866,7 +865,7 @@ public void TestReadLenStringValueTripleByteCharBufferBoundry1()
866865
public void TestReadLenStringValueTripleByteCharOne()
867866
{
868867
StringBuilder sb = new StringBuilder();
869-
sb.Append(euro, 1); //Just one triple byte char in the string.
868+
sb.Append(Euro, 1); //Just one triple byte char in the string.
870869

871870
string expected = sb.ToString();
872871
Assert.AreEqual(expected, WriteAndReadStringValue(expected));
@@ -877,9 +876,9 @@ public void TestReadLenStringValueTripleByteCharBufferBoundry2()
877876
{
878877
StringBuilder sb = new StringBuilder();
879878
sb.Append('1', 125);
880-
sb.Append(euro, 5); //last char of the eruo at the end of the boundry.
879+
sb.Append(Euro, 5); //last char of the eruo at the end of the boundry.
881880
sb.Append('1', 128);
882-
sb.Append(euro);
881+
sb.Append(Euro);
883882

884883
string expected = sb.ToString();
885884
Assert.AreEqual(expected, WriteAndReadStringValue(expected));
@@ -908,7 +907,7 @@ public void TestReadStringPropertyNameShortTripleByte()
908907
//sb.Append('1',127); //first char of euro at the end of the boundry.
909908
//sb.Append(euro, 5);
910909
//sb.Append('1',128);
911-
sb.Append(euro);
910+
sb.Append(Euro);
912911

913912
string expected = sb.ToString();
914913
Assert.AreEqual(expected, WriteAndReadStringPropertyName(expected));
@@ -919,9 +918,9 @@ public void TestReadStringPropertyNameTripleByteCharBufferBoundry0()
919918
{
920919
StringBuilder sb = new StringBuilder();
921920
sb.Append('1', 127); //first char of euro at the end of the boundry.
922-
sb.Append(euro, 5);
921+
sb.Append(Euro, 5);
923922
sb.Append('1', 128);
924-
sb.Append(euro);
923+
sb.Append(Euro);
925924

926925
string expected = sb.ToString();
927926
string result = WriteAndReadStringPropertyName(expected);
@@ -933,9 +932,9 @@ public void TestReadStringPropertyNameTripleByteCharBufferBoundry1()
933932
{
934933
StringBuilder sb = new StringBuilder();
935934
sb.Append('1', 126);
936-
sb.Append(euro, 5); //middle char of euro at the end of the boundry.
935+
sb.Append(Euro, 5); //middle char of euro at the end of the boundry.
937936
sb.Append('1', 128);
938-
sb.Append(euro);
937+
sb.Append(Euro);
939938

940939
string expected = sb.ToString();
941940
Assert.AreEqual(expected, WriteAndReadStringPropertyName(expected));
@@ -945,7 +944,7 @@ public void TestReadStringPropertyNameTripleByteCharBufferBoundry1()
945944
public void TestReadStringPropertyNameTripleByteCharOne()
946945
{
947946
StringBuilder sb = new StringBuilder();
948-
sb.Append(euro, 1); //Just one triple byte char in the string.
947+
sb.Append(Euro, 1); //Just one triple byte char in the string.
949948

950949
string expected = sb.ToString();
951950
Assert.AreEqual(expected, WriteAndReadStringPropertyName(expected));
@@ -956,9 +955,9 @@ public void TestReadStringPropertyNameTripleByteCharBufferBoundry2()
956955
{
957956
StringBuilder sb = new StringBuilder();
958957
sb.Append('1', 125);
959-
sb.Append(euro, 5); //last char of the eruo at the end of the boundry.
958+
sb.Append(Euro, 5); //last char of the eruo at the end of the boundry.
960959
sb.Append('1', 128);
961-
sb.Append(euro);
960+
sb.Append(Euro);
962961

963962
string expected = sb.ToString();
964963
Assert.AreEqual(expected, WriteAndReadStringPropertyName(expected));

Src/Newtonsoft.Json.Tests/Serialization/JsonSerializerTest.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,44 @@ public void ShouldSerializeTest()
33183318
Assert.AreEqual(27, deserialized.Age);
33193319
}
33203320

3321+
public class Employee
3322+
{
3323+
public string Name { get; set; }
3324+
public Employee Manager { get; set; }
3325+
3326+
public bool ShouldSerializeManager()
3327+
{
3328+
return (Manager != this);
3329+
}
3330+
}
3331+
3332+
[Test]
3333+
public void ShouldSerializeExample()
3334+
{
3335+
Employee joe = new Employee();
3336+
joe.Name = "Joe Employee";
3337+
Employee mike = new Employee();
3338+
mike.Name = "Mike Manager";
3339+
3340+
joe.Manager = mike;
3341+
mike.Manager = mike;
3342+
3343+
string json = JsonConvert.SerializeObject(new []{ joe, mike }, Formatting.Indented);
3344+
// [
3345+
// {
3346+
// "Name": "Joe Employee",
3347+
// "Manager": {
3348+
// "Name": "Mike Manager"
3349+
// }
3350+
// },
3351+
// {
3352+
// "Name": "Mike Manager"
3353+
// }
3354+
// ]
3355+
3356+
Console.WriteLine(json);
3357+
}
3358+
33213359
public class DictionaryKey
33223360
{
33233361
public string Value { get; set; }

Src/Newtonsoft.Json/Bson/BsonObjectId.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,21 @@
3131

3232
namespace Newtonsoft.Json.Bson
3333
{
34+
/// <summary>
35+
/// Represents a BSON Oid (object id).
36+
/// </summary>
3437
public class BsonObjectId
3538
{
39+
/// <summary>
40+
/// Gets or sets the value of the Oid.
41+
/// </summary>
42+
/// <value>The value of the Oid.</value>
3643
public byte[] Value { get; private set; }
3744

45+
/// <summary>
46+
/// Initializes a new instance of the <see cref="BsonObjectId"/> class.
47+
/// </summary>
48+
/// <param name="value">The Oid value.</param>
3849
public BsonObjectId(byte[] value)
3950
{
4051
ValidationUtils.ArgumentNotNull(value, "value");

Src/Newtonsoft.Json/Bson/BsonWriter.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ public override void WriteStartObject()
134134
AddParent(new BsonObject());
135135
}
136136

137+
/// <summary>
138+
/// Writes the property name of a name/value pair on a Json object.
139+
/// </summary>
140+
/// <param name="name">The name of the property.</param>
137141
public override void WritePropertyName(string name)
138142
{
139143
base.WritePropertyName(name);

Src/Newtonsoft.Json/Converters/BsonObjectIdConverter.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@
88

99
namespace Newtonsoft.Json.Converters
1010
{
11+
/// <summary>
12+
/// Converts a <see cref="BsonObjectId"/> to and from JSON and BSON.
13+
/// </summary>
1114
public class BsonObjectIdConverter : JsonConverter
1215
{
16+
/// <summary>
17+
/// Writes the JSON representation of the object.
18+
/// </summary>
19+
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
20+
/// <param name="value">The value.</param>
21+
/// <param name="serializer">The calling serializer.</param>
1322
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
1423
{
1524
BsonObjectId objectId = (BsonObjectId) value;
@@ -25,6 +34,14 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
2534
}
2635
}
2736

37+
/// <summary>
38+
/// Reads the JSON representation of the object.
39+
/// </summary>
40+
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
41+
/// <param name="objectType">Type of the object.</param>
42+
/// <param name="existingValue">The existing value of object being read.</param>
43+
/// <param name="serializer">The calling serializer.</param>
44+
/// <returns>The object value.</returns>
2845
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
2946
{
3047
if (reader.TokenType != JsonToken.Bytes)
@@ -35,6 +52,13 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
3552
return new BsonObjectId(value);
3653
}
3754

55+
/// <summary>
56+
/// Determines whether this instance can convert the specified object type.
57+
/// </summary>
58+
/// <param name="objectType">Type of the object.</param>
59+
/// <returns>
60+
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
61+
/// </returns>
3862
public override bool CanConvert(Type objectType)
3963
{
4064
return (objectType == typeof (BsonObjectId));

Src/Newtonsoft.Json/Converters/DataTableConverter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
6565
/// </summary>
6666
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
6767
/// <param name="objectType">Type of the object.</param>
68+
/// <param name="existingValue">The existing value of object being read.</param>
6869
/// <param name="serializer">The calling serializer.</param>
6970
/// <returns>The object value.</returns>
7071
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)

Src/Newtonsoft.Json/Converters/RegexConverter.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77

88
namespace Newtonsoft.Json.Converters
99
{
10+
/// <summary>
11+
/// Converts a <see cref="Regex"/> to and from JSON and BSON.
12+
/// </summary>
1013
public class RegexConverter : JsonConverter
1114
{
15+
/// <summary>
16+
/// Writes the JSON representation of the object.
17+
/// </summary>
18+
/// <param name="writer">The <see cref="JsonWriter"/> to write to.</param>
19+
/// <param name="value">The value.</param>
20+
/// <param name="serializer">The calling serializer.</param>
1221
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
1322
{
1423
Regex regex = (Regex) value;
@@ -63,6 +72,14 @@ private void WriteJson(JsonWriter writer, Regex regex)
6372
writer.WriteEndObject();
6473
}
6574

75+
/// <summary>
76+
/// Reads the JSON representation of the object.
77+
/// </summary>
78+
/// <param name="reader">The <see cref="JsonReader"/> to read from.</param>
79+
/// <param name="objectType">Type of the object.</param>
80+
/// <param name="existingValue">The existing value of object being read.</param>
81+
/// <param name="serializer">The calling serializer.</param>
82+
/// <returns>The object value.</returns>
6683
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
6784
{
6885
BsonReader bsonReader = reader as BsonReader;
@@ -119,6 +136,13 @@ private Regex ReadJson(JsonReader reader)
119136
return new Regex(pattern, (RegexOptions)options);
120137
}
121138

139+
/// <summary>
140+
/// Determines whether this instance can convert the specified object type.
141+
/// </summary>
142+
/// <param name="objectType">Type of the object.</param>
143+
/// <returns>
144+
/// <c>true</c> if this instance can convert the specified object type; otherwise, <c>false</c>.
145+
/// </returns>
122146
public override bool CanConvert(Type objectType)
123147
{
124148
return (objectType == typeof (Regex));

Src/Newtonsoft.Json/JsonConvert.cs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -739,17 +739,52 @@ public static void PopulateObject(string value, object target, JsonSerializerSet
739739
}
740740

741741
#if !NET20 && !SILVERLIGHT
742+
/// <summary>
743+
/// Serializes the <see cref="XNode"/> to a JSON string.
744+
/// </summary>
745+
/// <param name="node">The node to convert to JSON.</param>
746+
/// <returns>A JSON string of the XNode.</returns>
742747
public static string SerializeXNode(XObject node)
743748
{
744749
return SerializeXNode(node, Formatting.None);
745750
}
746751

752+
/// <summary>
753+
/// Serializes the <see cref="XNode"/> to a JSON string.
754+
/// </summary>
755+
/// <param name="node">The node to convert to JSON.</param>
756+
/// <param name="formatting">Indicates how the output is formatted.</param>
757+
/// <returns>A JSON string of the XNode.</returns>
747758
public static string SerializeXNode(XObject node, Formatting formatting)
748759
{
749760
XmlNodeConverter converter = new XmlNodeConverter();
750761

751762
return SerializeObject(node, formatting, converter);
752763
}
764+
765+
/// <summary>
766+
/// Deserializes the <see cref="XNode"/> from a JSON string.
767+
/// </summary>
768+
/// <param name="value">The JSON string.</param>
769+
/// <returns>The deserialized XNode</returns>
770+
public static XDocument DeserializeXNode(string value)
771+
{
772+
return DeserializeXNode(value, null);
773+
}
774+
775+
/// <summary>
776+
/// Deserializes the <see cref="XNode"/> from a JSON string nested in a root elment.
777+
/// </summary>
778+
/// <param name="value">The JSON string.</param>
779+
/// <param name="deserializeRootElementName">The name of the root element to append when deserializing.</param>
780+
/// <returns>The deserialized XNode</returns>
781+
public static XDocument DeserializeXNode(string value, string deserializeRootElementName)
782+
{
783+
XmlNodeConverter converter = new XmlNodeConverter();
784+
converter.DeserializeRootElementName = deserializeRootElementName;
785+
786+
return (XDocument)DeserializeObject(value, typeof(XDocument), converter);
787+
}
753788
#endif
754789

755790
#if !SILVERLIGHT
@@ -799,32 +834,6 @@ public static XmlDocument DeserializeXmlNode(string value, string deserializeRoo
799834

800835
return (XmlDocument)DeserializeObject(value, typeof(XmlDocument), converter);
801836
}
802-
803-
#if !NET20
804-
/// <summary>
805-
/// Deserializes the XNode from a JSON string.
806-
/// </summary>
807-
/// <param name="value">The JSON string.</param>
808-
/// <returns>The deserialized XmlNode</returns>
809-
public static XDocument DeserializeXNode(string value)
810-
{
811-
return DeserializeXNode(value, null);
812-
}
813-
814-
/// <summary>
815-
/// Deserializes the XmlNode from a JSON string nested in a root elment.
816-
/// </summary>
817-
/// <param name="value">The JSON string.</param>
818-
/// <param name="deserializeRootElementName">The name of the root element to append when deserializing.</param>
819-
/// <returns>The deserialized XmlNode</returns>
820-
public static XDocument DeserializeXNode(string value, string deserializeRootElementName)
821-
{
822-
XmlNodeConverter converter = new XmlNodeConverter();
823-
converter.DeserializeRootElementName = deserializeRootElementName;
824-
825-
return (XDocument)DeserializeObject(value, typeof(XDocument), converter);
826-
}
827-
#endif
828837
#endif
829838
}
830839
}

Src/Newtonsoft.Json/JsonPropertyAttribute.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public ObjectCreationHandling ObjectCreationHandling
5757
set { _objectCreationHandling = value; }
5858
}
5959

60+
/// <summary>
61+
/// Gets or sets the type name handling used when serializing this property.
62+
/// </summary>
63+
/// <value>The type name handling.</value>
6064
public TypeNameHandling TypeNameHandling
6165
{
6266
get { return _typeNameHandling ?? default(TypeNameHandling); }

0 commit comments

Comments
 (0)