This repository was archived by the owner on Jun 10, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Pass dictionary key to dictionary element visitors #50
Open
Deleted user (ghost)
wants to merge
26
commits into
develop
Choose a base branch
from
users/lgolding/visit-with-key-mf-design
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
7ee065b
Rename GenerateVisitNullCheckedMethod
larrygolding db326c7
Introduce GenerateVisitNullCheckedTwoArgumentMethod
larrygolding 84be68b
Add second parameter to two-parameter overload of VisitNullChecked.
larrygolding 09b80a7
Rename parameter type variables and hoist into class.
larrygolding d8c369f
Add ref keyword to second parameter.
larrygolding 578cb87
Remove body from one-argument overload.
larrygolding 6cc1333
Declare emptyKey.
larrygolding aa6e0aa
Add call to two-argument form.
larrygolding ee15cd2
Add generic type to call (not really needed) and arguments.
larrygolding 2ea7a28
Add second if statement
larrygolding 4fccf9b
Finish body of two-argument overload.
larrygolding 8d303c9
Add empty VisitDictionaryEntryMethod
larrygolding c9720dd
Add arguments to VisitDictionaryEntry.
larrygolding a0300ac
Add null parameter checks to GenerateVisitDictionaryEntry.
larrygolding 88dccd0
Unify null parameter checks.
larrygolding 94adbe2
Introduce GenerateDictionaryEntrySwitchSections.
larrygolding 61aef84
Generate switch sections in GenerateVisitDictionaryEntrySwitchSections.
larrygolding 30d6b5a
Add parameters to calls in GenerateVisitDictionaryEntrySwitchSections.
larrygolding 297ec43
Generate empty type dictionary entry visitor methods.
larrygolding 72ce442
Generate typed dictionary entry visitor method bodies.
larrygolding 3b7cd93
Add dictionary entry checking logic to class visitors.
larrygolding 3a325fe
Infer list of classes that occur as dictionary entries.
larrygolding ca3a5db
Update unit tests.
larrygolding c7c2136
Add a comment to SyntaxHelper.
larrygolding 79fddb8
Add comments to the new methods in SyntaxHelper.
larrygolding 21e1e76
Fix a mistake in a comment.
larrygolding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1419,7 +1419,7 @@ public virtual object VisitActual(ISNode node) | |
| { | ||
| if (node == null) | ||
| { | ||
| throw new ArgumentNullException(""node""); | ||
| throw new ArgumentNullException(nameof(node)); | ||
| } | ||
|
|
||
| switch (node.SNodeKind) | ||
|
|
@@ -1434,13 +1434,50 @@ public virtual object VisitActual(ISNode node) | |
| } | ||
|
|
||
| private T VisitNullChecked<T>(T node) where T : class, ISNode | ||
| { | ||
| string emptyKey = null; | ||
| return VisitNullChecked<T>(node, ref emptyKey); | ||
| } | ||
|
|
||
| private T VisitNullChecked<T>(T node, ref string key) where T : class, ISNode | ||
| { | ||
| if (node == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| return (T)Visit(node); | ||
| if (key == null) | ||
| { | ||
| return (T)Visit(node); | ||
| } | ||
|
|
||
| return (T)VisitDictionaryEntry(node, ref key); | ||
| } | ||
|
|
||
| private ISNode VisitDictionaryEntry(ISNode node, ref string key) | ||
| { | ||
| if (node == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(node)); | ||
| } | ||
|
|
||
| if (key == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(key)); | ||
| } | ||
|
|
||
| switch (node.SNodeKind) | ||
| { | ||
| case SNodeKind.D: | ||
| return VisitDDictionaryEntry((D)node, ref key); | ||
| default: | ||
| throw new InvalidOperationException(); | ||
| } | ||
| } | ||
|
|
||
| public virtual D VisitDDictionaryEntry(D node, ref string key) | ||
| { | ||
| return (D)Visit(node); | ||
| } | ||
|
|
||
| public virtual C VisitC(C node) | ||
|
|
@@ -1479,7 +1516,13 @@ public virtual C VisitC(C node) | |
| var value = node.DictionaryWithObjectSchemaProp[key]; | ||
| if (value != null) | ||
| { | ||
| node.DictionaryWithObjectSchemaProp[key] = VisitNullChecked(value); | ||
| string newKey = key; | ||
| node.DictionaryWithObjectSchemaProp.Remove(key); | ||
| value = VisitNullChecked(value, ref newKey); | ||
| if (newKey != null) | ||
| { | ||
| node.DictionaryWithObjectSchemaProp[newKey] = VisitNullChecked(value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1508,7 +1551,13 @@ public virtual C VisitC(C node) | |
| var value = node.DictionaryWithUriKeyProp[key]; | ||
| if (value != null) | ||
| { | ||
| node.DictionaryWithUriKeyProp[key] = VisitNullChecked(value); | ||
| string newKey = key; | ||
| node.DictionaryWithUriKeyProp.Remove(key); | ||
| value = VisitNullChecked(value, ref newKey); | ||
| if (newKey != null) | ||
| { | ||
| node.DictionaryWithUriKeyProp[newKey] = VisitNullChecked(value); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -2675,7 +2724,7 @@ public virtual object VisitActual(ISNode node) | |
| { | ||
| if (node == null) | ||
| { | ||
| throw new ArgumentNullException(""node""); | ||
| throw new ArgumentNullException(nameof(node)); | ||
| } | ||
|
|
||
| switch (node.SNodeKind) | ||
|
|
@@ -2688,13 +2737,43 @@ public virtual object VisitActual(ISNode node) | |
| } | ||
|
|
||
| private T VisitNullChecked<T>(T node) where T : class, ISNode | ||
| { | ||
| string emptyKey = null; | ||
| return VisitNullChecked<T>(node, ref emptyKey); | ||
| } | ||
|
|
||
| private T VisitNullChecked<T>(T node, ref string key) where T : class, ISNode | ||
| { | ||
| if (node == null) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| return (T)Visit(node); | ||
| if (key == null) | ||
| { | ||
| return (T)Visit(node); | ||
| } | ||
|
|
||
| return (T)VisitDictionaryEntry(node, ref key); | ||
| } | ||
|
|
||
| private ISNode VisitDictionaryEntry(ISNode node, ref string key) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If no schema properties are defined as dictionaries of schema-defined types (as in this test), there's no reason to emit this method or the two-argument overload to |
||
| { | ||
| if (node == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(node)); | ||
| } | ||
|
|
||
| if (key == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(key)); | ||
| } | ||
|
|
||
| switch (node.SNodeKind) | ||
| { | ||
| default: | ||
| throw new InvalidOperationException(); | ||
| } | ||
| } | ||
|
|
||
| public virtual C VisitC(C node) | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a nice change