generated from kasthack-labs/dotnet-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add max depth, add dictionary handling, add support for zeros in arra…
…ys, bump package version to 1.0.7
- Loading branch information
Showing
7 changed files
with
265 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace kasthack.NotEmpty.Core | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
/// <summary> | ||
/// Dispose doesn't do what you migth think. | ||
/// </summary> | ||
internal class AssertContext | ||
{ | ||
private readonly Stack<string> pathSegments = new(); | ||
|
||
public AssertOptions Options { get; } | ||
|
||
public int CurrentDepth => this.pathSegments.Count; | ||
|
||
public string Path => string.Concat(this.pathSegments); | ||
|
||
public bool IsArrayElement { get; set; } = false; | ||
|
||
public AssertContext(AssertOptions options) => this.Options = options; | ||
|
||
public IDisposable EnterPath(string segment, bool isArray) => new PathContext(this, segment, isArray); | ||
|
||
private struct PathContext : IDisposable | ||
{ | ||
private readonly AssertContext context; | ||
private readonly bool originalIsArrayElement; | ||
private bool disposed = false; | ||
|
||
public PathContext(AssertContext context, string segment, bool isArray) | ||
{ | ||
this.context = context ?? throw new ArgumentNullException(nameof(context)); | ||
this.originalIsArrayElement = this.context.IsArrayElement; | ||
|
||
this.context.pathSegments.Push(segment); | ||
this.context.IsArrayElement = isArray; | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (!this.disposed) | ||
{ | ||
this.disposed = true; | ||
this.context.pathSegments.Pop(); | ||
this.context.IsArrayElement = this.originalIsArrayElement; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.