Skip to content

Commit

Permalink
Merge pull request #202 from SceneGate/feature/196-changeformat-fluent
Browse files Browse the repository at this point in the history
✨  ChangeFormat fluent style returning itself
  • Loading branch information
pleonex committed Nov 24, 2023
2 parents 38e4d7b + d662676 commit 49038fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Yarhl.UnitTests/FileSystem/NodeTests.cs
Expand Up @@ -137,9 +137,10 @@ public void ChangeFormat()
var dummyFormat1 = new StringFormat("3");
var dummyFormat2 = new IntFormat(4);
using var node = new Node("mytest", dummyFormat1);
node.ChangeFormat(dummyFormat2);
Node output = node.ChangeFormat(dummyFormat2);
Assert.AreNotSame(node.Format, dummyFormat1);
Assert.AreSame(node.Format, dummyFormat2);
Assert.AreSame(node, output);
}

[Test]
Expand Down
7 changes: 5 additions & 2 deletions src/Yarhl/FileSystem/Node.cs
Expand Up @@ -124,6 +124,7 @@ public Node(Node node)
/// <summary>
/// Change the format of the current node.
/// </summary>
/// <returns>This node.</returns>
/// <remarks>
/// <para>If the previous format was a container, this method will
/// remove the children of the node.
Expand All @@ -137,14 +138,14 @@ public Node(Node node)
/// If <see langword="true" /> the method will dispose the previous
/// format.
/// </param>
public void ChangeFormat(IFormat? newFormat, bool disposePreviousFormat = true)
public Node ChangeFormat(IFormat? newFormat, bool disposePreviousFormat = true)
{
if (Disposed) {
throw new ObjectDisposedException(nameof(Node));
}

if (newFormat == Format) {
return;
return this;
}

// If it was a container, clean children
Expand All @@ -162,6 +163,8 @@ public void ChangeFormat(IFormat? newFormat, bool disposePreviousFormat = true)
if (IsContainer) {
AddContainerChildren();
}

return this;
}

/// <summary>
Expand Down

0 comments on commit 49038fe

Please sign in to comment.