Skip to content

Commit 05cd2a2

Browse files
author
Oren (electricessence)
committed
AddValue
1 parent 3612048 commit 05cd2a2

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

Node.Factory.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public Node<T> GetBlankNode()
4242
return n;
4343
}
4444

45+
/// <summary>
46+
/// Gets a blank node.
47+
/// </summary>
48+
/// <returns>A blank node.</returns>
49+
public Node<T> GetNodeWithValue(T value)
50+
{
51+
var n = GetBlankNode();
52+
n.Value = value;
53+
return n;
54+
}
4555

4656
/// <summary>
4757
/// Recycles the node into the object pool, returning the value contained.

Node.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public void Clear()
139139
_children.Clear();
140140
}
141141

142-
143142
/// <inheritdoc />
144143
public int Count => _children.Count;
145144

@@ -159,6 +158,16 @@ public void CopyTo(Node<T>[] array, int arrayIndex)
159158
}
160159
#endregion
161160

161+
/// <summary>
162+
/// Gets a new node with the provided value and adds it as a child.
163+
/// </summary>
164+
/// <param name="value">The value of the new child.</param>
165+
public void AddValue(T value)
166+
{
167+
AssertNotRecycled();
168+
Add(_factory.GetNodeWithValue(value));
169+
}
170+
162171
/// <summary>
163172
/// Replaces an existing node within it's tree with another node.
164173
/// </summary>

Open.Hierarchy.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Part of the "Open" set of libraries.</Description>
1414
<RepositoryUrl>https://github.com/electricessence/Open.Hierarchy/</RepositoryUrl>
1515
<RepositoryType>git</RepositoryType>
1616
<PackageTags>dotnet, dotnetcore, cs, tree, node, hierarchy, parent, child, root</PackageTags>
17-
<Version>1.4.3</Version>
18-
<PackageReleaseNotes>API simplification and improvments to deferred mapping.</PackageReleaseNotes>
17+
<Version>1.4.4</Version>
18+
<PackageReleaseNotes>Added useful node creation methods.</PackageReleaseNotes>
1919
</PropertyGroup>
2020

2121
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

0 commit comments

Comments
 (0)