Skip to content

Commit 1da3895

Browse files
committed
#29 Added Slice methods to Children.
1 parent 7f61fb1 commit 1da3895

13 files changed

Lines changed: 366 additions & 12 deletions

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
uses: MrKWatkins/dotnet-build@main
3030
with:
3131
name: Examples
32-
directory: ./examples
32+
directory: examples
3333
coverage-run-settings: coverage.runsettings
3434

3535
- name: Build Documentation

doc/MrKWatkins.Ast.tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<toc-element toc-title="Add" topic="MrKWatkins.Ast.Children-1.Add.md" />
2626
<toc-element toc-title="Clear" topic="MrKWatkins.Ast.Children-1.Clear.md" />
2727
<toc-element toc-title="Contains" topic="MrKWatkins.Ast.Children-1.Contains.md" />
28+
<toc-element toc-title="EnumerateSlice" topic="MrKWatkins.Ast.Children-1.EnumerateSlice.md" />
2829
<toc-element toc-title="ExceptOfType" topic="MrKWatkins.Ast.Children-1.ExceptOfType.md" />
2930
<toc-element toc-title="FirstIfTypeOrDefault" topic="MrKWatkins.Ast.Children-1.FirstIfTypeOrDefault.md" />
3031
<toc-element toc-title="FirstOfType" topic="MrKWatkins.Ast.Children-1.FirstOfType.md" />
@@ -42,7 +43,9 @@
4243
<toc-element toc-title="Replace" topic="MrKWatkins.Ast.Children-1.Replace.md" />
4344
<toc-element toc-title="SingleOfType" topic="MrKWatkins.Ast.Children-1.SingleOfType.md" />
4445
<toc-element toc-title="SingleOfTypeOrDefault" topic="MrKWatkins.Ast.Children-1.SingleOfTypeOrDefault.md" />
46+
<toc-element toc-title="Slice" topic="MrKWatkins.Ast.Children-1.Slice.md" />
4547
<toc-element toc-title="UnsafeGet" topic="MrKWatkins.Ast.Children-1.UnsafeGet.md" />
48+
<toc-element toc-title="UnsafeSlice" topic="MrKWatkins.Ast.Children-1.UnsafeSlice.md" />
4649
</toc-element>
4750
</toc-element>
4851
<toc-element toc-title="DefaultNodeFactory&lt;TNode&gt;">
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Children&lt;TNode&gt;.EnumerateSlice Method
2+
## Overloads
3+
4+
| Name | Description |
5+
| ---- | ----------- |
6+
| [EnumerateSlice(Int32, Int32)](MrKWatkins.Ast.Children-1.EnumerateSlice.md#mrkwatkins-ast-children-1-enumerateslice(system-int32-system-int32)) | Returns a lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). |
7+
| [EnumerateSlice(Range)](MrKWatkins.Ast.Children-1.EnumerateSlice.md#mrkwatkins-ast-children-1-enumerateslice(system-range)) | Returns a lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). |
8+
9+
## EnumerateSlice(Int32, Int32) {id="mrkwatkins-ast-children-1-enumerateslice(system-int32-system-int32)"}
10+
11+
Returns a lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).
12+
13+
```c#
14+
public IEnumerable<TNode> EnumerateSlice(int index, int count);
15+
```
16+
17+
## Parameters {id="parameters-mrkwatkins-ast-children-1-enumerateslice(system-int32-system-int32)"}
18+
19+
| Name | Type | Description |
20+
| ---- | ---- | ----------- |
21+
| index | [Int32](https://learn.microsoft.com/en-gb/dotnet/api/System.Int32) | The zero-based index at which the range starts. |
22+
| count | [Int32](https://learn.microsoft.com/en-gb/dotnet/api/System.Int32) | The number of nodes in the range. |
23+
24+
## Returns {id="returns-mrkwatkins-ast-children-1-enumerateslice(system-int32-system-int32)"}
25+
26+
[IEnumerable&lt;TNode&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.Collections.Generic.IEnumerable-1)
27+
28+
A lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).
29+
## EnumerateSlice(Range) {id="mrkwatkins-ast-children-1-enumerateslice(system-range)"}
30+
31+
Returns a lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).
32+
33+
```c#
34+
public IEnumerable<TNode> EnumerateSlice(Range range);
35+
```
36+
37+
## Parameters {id="parameters-mrkwatkins-ast-children-1-enumerateslice(system-range)"}
38+
39+
| Name | Type | Description |
40+
| ---- | ---- | ----------- |
41+
| range | [Range](https://learn.microsoft.com/en-gb/dotnet/api/System.Range) | The [Range](https://learn.microsoft.com/en-gb/dotnet/api/System.Range). |
42+
43+
## Returns {id="returns-mrkwatkins-ast-children-1-enumerateslice(system-range)"}
44+
45+
[IEnumerable&lt;TNode&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.Collections.Generic.IEnumerable-1)
46+
47+
A lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).

doc/topics/API/MrKWatkins.Ast.Children-1.Replace.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Children&lt;TNode&gt;.Replace Method
22
## Definition
33

4-
Replaces a node in the collection with another node. The replacement will be removed from its parent and the node being replaced will have it&#39;s parent removed.
4+
Replaces a node in the collection with another node. The replacement will be removed from its parent and the node being replaced will have its parent removed.
55

66
```c#
77
public void Replace(TNode child, TNode replacement);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Children&lt;TNode&gt;.Slice Method
2+
## Definition
3+
4+
Creates a shallow copy of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).
5+
6+
```c#
7+
public TNode[] Slice(int index, int count);
8+
```
9+
10+
## Parameters
11+
12+
| Name | Type | Description |
13+
| ---- | ---- | ----------- |
14+
| index | [Int32](https://learn.microsoft.com/en-gb/dotnet/api/System.Int32) | The zero-based index at which the range starts. |
15+
| count | [Int32](https://learn.microsoft.com/en-gb/dotnet/api/System.Int32) | The number of nodes in the range. |
16+
17+
## Returns
18+
19+
TNode\[\]
20+
21+
A shallow copy of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Children&lt;TNode&gt;.UnsafeSlice Method
2+
## Overloads
3+
4+
| Name | Description |
5+
| ---- | ----------- |
6+
| [UnsafeSlice(Int32, Int32)](MrKWatkins.Ast.Children-1.UnsafeSlice.md#mrkwatkins-ast-children-1-unsafeslice(system-int32-system-int32)) | Returns a [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). Nodes should not be added or removed from the [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md) while the [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) is in use. |
7+
| [UnsafeSlice(Range)](MrKWatkins.Ast.Children-1.UnsafeSlice.md#mrkwatkins-ast-children-1-unsafeslice(system-range)) | Returns a [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). Nodes should not be added or removed from the [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md) while the [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) is in use. |
8+
9+
## UnsafeSlice(Int32, Int32) {id="mrkwatkins-ast-children-1-unsafeslice(system-int32-system-int32)"}
10+
11+
Returns a [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). Nodes should not be added or removed from the [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md) while the [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) is in use.
12+
13+
```c#
14+
public ReadOnlySpan<TNode> UnsafeSlice(int index, int count);
15+
```
16+
17+
## Parameters {id="parameters-mrkwatkins-ast-children-1-unsafeslice(system-int32-system-int32)"}
18+
19+
| Name | Type | Description |
20+
| ---- | ---- | ----------- |
21+
| index | [Int32](https://learn.microsoft.com/en-gb/dotnet/api/System.Int32) | The zero-based index at which the range starts. |
22+
| count | [Int32](https://learn.microsoft.com/en-gb/dotnet/api/System.Int32) | The number of nodes in the range. |
23+
24+
## Returns {id="returns-mrkwatkins-ast-children-1-unsafeslice(system-int32-system-int32)"}
25+
26+
[ReadOnlySpan&lt;TNode&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1)
27+
28+
A [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).
29+
## UnsafeSlice(Range) {id="mrkwatkins-ast-children-1-unsafeslice(system-range)"}
30+
31+
Returns a [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). Nodes should not be added or removed from the [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md) while the [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) is in use.
32+
33+
```c#
34+
public ReadOnlySpan<TNode> UnsafeSlice(Range range);
35+
```
36+
37+
## Parameters {id="parameters-mrkwatkins-ast-children-1-unsafeslice(system-range)"}
38+
39+
| Name | Type | Description |
40+
| ---- | ---- | ----------- |
41+
| range | [Range](https://learn.microsoft.com/en-gb/dotnet/api/System.Range) | The [Range](https://learn.microsoft.com/en-gb/dotnet/api/System.Range). |
42+
43+
## Returns {id="returns-mrkwatkins-ast-children-1-unsafeslice(system-range)"}
44+
45+
[ReadOnlySpan&lt;TNode&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1)
46+
47+
A [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md).

doc/topics/API/MrKWatkins.Ast.Children-1.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public sealed class Children<TNode> : IList<TNode>, ICollection<TNode>, IEnumera
3838
| [Add(TNode\[\])](MrKWatkins.Ast.Children-1.Add.md#mrkwatkins-ast-children-1-add(-0())) | Adds nodes to the collection and assigns their [Parent](MrKWatkins.Ast.Node-1.Parent.md) properties. |
3939
| [Clear()](MrKWatkins.Ast.Children-1.Clear.md) | Removes all nodes from the collection and resets their [Parent](MrKWatkins.Ast.Node-1.Parent.md) properties to `null`. |
4040
| [Contains(TNode)](MrKWatkins.Ast.Children-1.Contains.md) | Determines if the specified node is in the collection or not. |
41+
| [EnumerateSlice(Int32, Int32)](MrKWatkins.Ast.Children-1.EnumerateSlice.md#mrkwatkins-ast-children-1-enumerateslice(system-int32-system-int32)) | Returns a lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). |
42+
| [EnumerateSlice(Range)](MrKWatkins.Ast.Children-1.EnumerateSlice.md#mrkwatkins-ast-children-1-enumerateslice(system-range)) | Returns a lazy enumeration of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). |
4143
| [ExceptOfType&lt;TChild&gt;()](MrKWatkins.Ast.Children-1.ExceptOfType.md) | Lazily enumerates over all nodes in this collection not of the specified type. |
4244
| [FirstIfTypeOrDefault&lt;TChild&gt;(TChild)](MrKWatkins.Ast.Children-1.FirstIfTypeOrDefault.md) | Returns the first node in the collection if it is of the specified type or a specified default if the collection is empty or the first node is a different type. |
4345
| [FirstOfType&lt;TChild&gt;()](MrKWatkins.Ast.Children-1.FirstOfType.md) | Returns the first node in the collection of the specified type or throws otherwise. |
@@ -54,8 +56,11 @@ public sealed class Children<TNode> : IList<TNode>, ICollection<TNode>, IEnumera
5456
| [OfType&lt;TChild&gt;()](MrKWatkins.Ast.Children-1.OfType.md) | Lazily enumerates over all nodes in this collection of the specified type. |
5557
| [Remove(TNode)](MrKWatkins.Ast.Children-1.Remove.md) | Tries to remove a node from the collection and reset its [Parent](MrKWatkins.Ast.Node-1.Parent.md) property to `null`. |
5658
| [RemoveAt(Int32)](MrKWatkins.Ast.Children-1.RemoveAt.md) | Removes the node at the specified position from the collection and reset its [Parent](MrKWatkins.Ast.Node-1.Parent.md) property to `null`. |
57-
| [Replace(TNode, TNode)](MrKWatkins.Ast.Children-1.Replace.md) | Replaces a node in the collection with another node. The replacement will be removed from its parent and the node being replaced will have it&#39;s parent removed. |
59+
| [Replace(TNode, TNode)](MrKWatkins.Ast.Children-1.Replace.md) | Replaces a node in the collection with another node. The replacement will be removed from its parent and the node being replaced will have its parent removed. |
5860
| [SingleOfType&lt;TChild&gt;()](MrKWatkins.Ast.Children-1.SingleOfType.md) | Returns the only node in the collection of the specified type. Throws if there is not exactly one node in the collection of the specified type. |
5961
| [SingleOfTypeOrDefault&lt;TChild&gt;(TChild)](MrKWatkins.Ast.Children-1.SingleOfTypeOrDefault.md) | Returns the only node in the collection of the specified type. Returns the specified default if there are no nodes in the collection of the specified type. Throws if there are multiple nodes in the collection of the specified type. |
62+
| [Slice(Int32, Int32)](MrKWatkins.Ast.Children-1.Slice.md) | Creates a shallow copy of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). |
6063
| [UnsafeGet(Int32)](MrKWatkins.Ast.Children-1.UnsafeGet.md) | Gets the child at the specified index in the collection without array bounds checks. For high performance scenarios. WARNING: Do not use unless you are certain of the number of children! |
64+
| [UnsafeSlice(Int32, Int32)](MrKWatkins.Ast.Children-1.UnsafeSlice.md#mrkwatkins-ast-children-1-unsafeslice(system-int32-system-int32)) | Returns a [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). Nodes should not be added or removed from the [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md) while the [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) is in use. |
65+
| [UnsafeSlice(Range)](MrKWatkins.Ast.Children-1.UnsafeSlice.md#mrkwatkins-ast-children-1-unsafeslice(system-range)) | Returns a [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) of a range of nodes in the source [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md). Nodes should not be added or removed from the [Children&lt;TNode&gt;](MrKWatkins.Ast.Children-1.md) while the [ReadOnlySpan&lt;T&gt;](https://learn.microsoft.com/en-gb/dotnet/api/System.ReadOnlySpan-1) is in use. |
6166

doc/topics/API/MrKWatkins.Ast.MessageFormatter.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Utility methods to format [Messages](MrKWatkins.Ast.Message.md) as strings. Formatting optionally includes the original source code.
55

66
```c#
7-
public abstract sealed class MessageFormatter
7+
public static class MessageFormatter
88
```
99

1010
## Methods

examples/Directory.Build.props

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@
2222
</ItemGroup>
2323

2424
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('Tests'))">
25-
<PackageReference Include="coverlet.collector">
26-
<PrivateAssets>all</PrivateAssets>
27-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
28-
</PackageReference>
2925
<PackageReference Include="FluentAssertions"/>
3026
<PackageReference Include="Microsoft.NET.Test.Sdk"/>
3127
<PackageReference Include="NUnit"/>

examples/Directory.Packages.props

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
66
</PropertyGroup>
77
<ItemGroup>
8-
<PackageVersion Include="coverlet.collector" Version="6.0.2"/>
98
<PackageVersion Include="FluentAssertions" Version="7.0.0"/>
109
<PackageVersion Include="JetBrains.Annotations" Version="2024.3.0"/>
1110
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0"/>
12-
<PackageVersion Include="NUnit" Version="4.3.0"/>
11+
<PackageVersion Include="NUnit" Version="4.3.1"/>
1312
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0"/>
1413
</ItemGroup>
1514
</Project>

0 commit comments

Comments
 (0)