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
Copy file name to clipboardExpand all lines: _docs/pointer/basics.md
+50-1Lines changed: 50 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ It also supports a URL format, which is essentially the same thing, except that
50
50
51
51
## In code {#pointer-in-code}
52
52
53
-
The `JsonPointer`struct is the model for JSON Pointer.
53
+
The `JsonPointer`class is the model for JSON Pointer.
54
54
55
55
There are three ways create pointers:
56
56
@@ -87,6 +87,55 @@ var success = pointer.TryEvaluate(element, out var result);
87
87
> The designers of the `JsonNode` API have elected (for [reasons](https://github.com/dotnet/designs/blob/40794be63ecd8b35e9596412050a84dedd575b99/accepted/2020/serializer/WriteableDomAndDynamic.md#missing-vs-null) I [disagree](https://github.com/dotnet/runtime/issues/66948#issuecomment-1080148457) with) to consider JSON null and .Net null to be equivalent. This goes against both my personal experience building Manatee.Json and the `JsonElement` API, both of which maintain a separation between these two null concepts. Because of the unified design, it's impossible to determine whether a returned `JsonNode` value of `null` represents a value that is present but null or it is merely absent from the data. To accommodate this, the evaluation method can only support the familiar `TryParse()` signature. A return of `true` indicates the value was found, and `false` indicates it was not. In the case of a `true` return, `result` may still be null, indicating the value was found and was a JSON null.
88
88
{: .prompt-info }
89
89
90
+
### Pointer math
91
+
92
+
You can also combine and augment pointers in different ways.
93
+
94
+
Joining two pointers together:
95
+
96
+
```c#
97
+
varpointer1=JsonPointer.Parse("/objects/and");
98
+
varpointer2=JsonPointer.Parse("/3/arrays");
99
+
varfinal=pointer1.Combine(pointer2);
100
+
```
101
+
102
+
Appending additional segments to an existing pointer:
103
+
104
+
```c#
105
+
varpointer=JsonPointer.Parse("/objects/and");
106
+
varfinal=pointer1.Combine(3, "arrays");
107
+
```
108
+
109
+
### Access pointer parts and create sub-pointers
110
+
111
+
You can retrieve the individual segments using the indexer:
There are also method versions of this functionality, which are also available if you're not yet using .Net 8: `.GetAncestor(int)` and `.GetLocal()`.
135
+
136
+
> Accessing pointers acts like accessing strings: getting segments has no allocations (like getting a `char` via the string's `int` indexer), but creating a sub-pointer _does_ allocate a new `JsonPointer` instance (like creating a substring via the string's `Range` indexer).
137
+
{: .prompt-info }
138
+
90
139
### Building pointers using Linq expressions {#linq}
91
140
92
141
When building a pointer using the `Create<T>()` method which takes a Linq expression, there are a couple of things to be aware of.
0 commit comments