C#: Add StructuralEqualityComparator to SDK#7009
Merged
knutwannheden merged 4 commits intomainfrom Mar 17, 2026
Merged
Conversation
Provides a public static method for comparing two J (LST) nodes for structural equality, ignoring whitespace, formatting, markers, node IDs, and type attribution. Reuses TreeHelper from the pattern matching engine.
Move HasNullSafe, IsRightPadded, IsLeftPadded, IsContainer to TreeHelper to eliminate duplication between StructuralEqualityComparator and PatternMatchingComparator. Cache PropertyInfo lookups in UnwrapPadded and GetContainerElements. Optimize generic type dispatch in CompareValues to call GetType() once per value instead of up to three times.
Update class summary to note that most markers are ignored but semantic markers like NullSafe (distinguishing ?. from .) are explicitly compared.
StructuralEqualityComparator to SDK
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StructuralEqualityComparator— a public static class for comparing twoJ(LST) nodes for structural equality, ignoring whitespace, formatting, node IDs, and type attributionHasNullSafe,IsRightPadded,IsLeftPadded,IsContainer) fromPatternMatchingComparatorintoTreeHelper, eliminating duplicationPropertyInfolookups inTreeHelper.UnwrapPaddedandGetContainerElementsfor better hot-path performanceMotivation
Recipe authors in
recipes-csharpneed to compare AST subtrees for structural equality (e.g., checking if both sides ofx ?? xare identical, or if if/else branches match). The existingPatternMatchingComparatorhandles this internally but isinternaland carries capture/placeholder/variadic overhead not needed for simple equality checks.Usage
Test plan