You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// This contains the functionality to manipulate a JSON blob
11
+
/// </summary>
12
+
publicclassJsonWriter:ITemplateWriter
10
13
{
11
14
privateJObject_rootNode;
12
15
@@ -15,18 +18,19 @@ public JsonWriter()
15
18
_rootNode=newJObject();
16
19
}
17
20
18
-
publicJsonWriter(JObjectrootNode)
19
-
{
20
-
_rootNode=rootNode;
21
-
}
22
-
21
+
/// <summary>
22
+
/// Checks if the dot(.) seperated jsonPath exists in the json blob stored at the _rootNode
23
+
/// </summary>
24
+
/// <param name="jsonPath">dot(.) seperated path. Example "Person.Name.FirstName"</param>
25
+
/// <returns>true if the path exist, else false</returns>
26
+
/// <exception cref="InvalidDataException">Thrown if the jsonPath is invalid</exception>
23
27
publicboolExists(stringjsonPath)
24
28
{
25
29
if(!IsValidPath(jsonPath))
26
30
{
27
31
thrownewInvalidDataException($"'{jsonPath}' is not a valid '{nameof(jsonPath)}'");
28
32
}
29
-
33
+
30
34
JTokencurrentNode=_rootNode;
31
35
foreach(varpropertyinjsonPath.Split('.'))
32
36
{
@@ -40,7 +44,17 @@ public bool Exists(string jsonPath)
40
44
returncurrentNode!=null;
41
45
}
42
46
43
-
publicvoidSetToken(stringjsonPath,JTokentoken)
47
+
/// <summary>
48
+
/// This method converts the supplied token it into a <see cref="JToken"/> type and sets it at the dot(.) seperated jsonPath.
49
+
/// Any non-existing nodes in the jsonPath are created on the fly.
50
+
/// All non-terminal nodes in the jsonPath need to be of type <see cref="JObject"/>.
51
+
/// </summary>
52
+
/// <param name="jsonPath">dot(.) seperated path. Example "Person.Name.FirstName"</param>
53
+
/// <param name="token">The object to set at the specified jsonPath</param>
54
+
/// <param name="tokenType"><see cref="TokenType"/>This does not play any role while setting a token for the JsonWriter</param>
55
+
/// <exception cref="InvalidDataException">Thrown if the jsonPath is invalid</exception>
56
+
/// <exception cref="InvalidOperationException">Thrown if the terminal property in the jsonPath is null/empty or if any non-terminal nodes in the jsonPath cannot be converted to <see cref="JObject"/></exception>
/// Gets the object stored at the dot(.) seperated jsonPath. If the path does not exist then return the defaultToken.
129
+
/// The defaultToken is only returned if it holds a non-null value.
130
+
/// The object is deserialized into type T before being returned.
131
+
/// </summary>
132
+
/// <param name="jsonPath">dot(.) seperated path. Example "Person.Name.FirstName"</param>
133
+
/// <param name="defaultToken">The object that is returned if jsonPath does not exist in the JSON blob. It will be convert to type T before being returned.</param>
134
+
/// <exception cref="InvalidOperationException">Thrown if the jsonPath does not exist and the defaultToken is null</exception>
0 commit comments