Skip to content
This repository was archived by the owner on Jun 10, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7ee065b
Rename GenerateVisitNullCheckedMethod
larrygolding Sep 21, 2018
db326c7
Introduce GenerateVisitNullCheckedTwoArgumentMethod
larrygolding Sep 21, 2018
84be68b
Add second parameter to two-parameter overload of VisitNullChecked.
larrygolding Sep 21, 2018
09b80a7
Rename parameter type variables and hoist into class.
larrygolding Sep 21, 2018
d8c369f
Add ref keyword to second parameter.
larrygolding Sep 21, 2018
578cb87
Remove body from one-argument overload.
larrygolding Sep 21, 2018
6cc1333
Declare emptyKey.
larrygolding Sep 22, 2018
aa6e0aa
Add call to two-argument form.
larrygolding Sep 22, 2018
ee15cd2
Add generic type to call (not really needed) and arguments.
larrygolding Sep 22, 2018
2ea7a28
Add second if statement
larrygolding Sep 22, 2018
4fccf9b
Finish body of two-argument overload.
larrygolding Sep 22, 2018
8d303c9
Add empty VisitDictionaryEntryMethod
larrygolding Sep 22, 2018
c9720dd
Add arguments to VisitDictionaryEntry.
larrygolding Sep 22, 2018
a0300ac
Add null parameter checks to GenerateVisitDictionaryEntry.
larrygolding Sep 22, 2018
88dccd0
Unify null parameter checks.
larrygolding Sep 22, 2018
94adbe2
Introduce GenerateDictionaryEntrySwitchSections.
larrygolding Sep 22, 2018
61aef84
Generate switch sections in GenerateVisitDictionaryEntrySwitchSections.
larrygolding Sep 22, 2018
30d6b5a
Add parameters to calls in GenerateVisitDictionaryEntrySwitchSections.
larrygolding Sep 22, 2018
297ec43
Generate empty type dictionary entry visitor methods.
larrygolding Sep 22, 2018
72ce442
Generate typed dictionary entry visitor method bodies.
larrygolding Sep 22, 2018
3b7cd93
Add dictionary entry checking logic to class visitors.
larrygolding Sep 23, 2018
3a325fe
Infer list of classes that occur as dictionary entries.
larrygolding Sep 23, 2018
ca3a5db
Update unit tests.
larrygolding Sep 24, 2018
c7c2136
Add a comment to SyntaxHelper.
larrygolding Sep 24, 2018
79fddb8
Add comments to the new methods in SyntaxHelper.
larrygolding Sep 24, 2018
21e1e76
Fix a mistake in a comment.
larrygolding Sep 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 85 additions & 6 deletions src/Json.Schema.ToDotNet.UnitTests/DataModelGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ public virtual object VisitActual(ISNode node)
{
if (node == null)
{
throw new ArgumentNullException(""node"");
throw new ArgumentNullException(nameof(node));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nameof(node) [](start = 48, length = 12)

this is a nice change

}

switch (node.SNodeKind)
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)

@ghost Deleted user (ghost) Sep 24, 2018

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VisitDictionaryEntry [](start = 23, length = 20)

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 VisitNullChecked. I suggest we not further complicate the code generator by optimizing for this. #ByDesign

{
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)
Expand Down
Loading