fix(C#): added dependency usings based on types present in renderContext #2606
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.
Description
change - forcing dependency namespace (
"System.Collections.Generic"
) to be added for list and dictionary in cases where common namespace addition(CSharpRenderer.emitUsings
) was skippedRelated Issue
#2523
Motivation and Context
#2523
Previous Behaviour / Output
if you run the C# renderer with --features just-types --array-type list then it creates List properties, but doesn't add the required using System.Collections.Generic;. It also happens without the --array-type list if a Dictionary<K,V> is generated as a property.
command:
echo '{ "name": "David","keyval":{"1":{"prop1":1},"2":{"prop1":1},"3":{"prop1":3}} }' | script/quicktype -l csharp --features just-types
output:
command:
echo '{ "name": "David","arr":[1,2,3] }' | script/quicktype -l csharp --features just-types --array-type list
output:
New Behaviour / Output
with new change
using System.Collections.Generic
gets added inside name space before class definition when requiredcommand:
echo '{ "name": "David","keyval":{"1":{"prop1":1},"2":{"prop1":1},"3":{"prop1":3}} }' | script/quicktype -l csharp --features just-types
output:
command:
echo '{ "name": "David","arr":[1,2,3] }' | script/quicktype -l csharp --features just-types --array-type list
output:
How Has This Been Tested?
Manual testing using command line, covered negative and positive cases of examples provided above
[EDIT] - tested with both array and dictionary present in json to validate single
using System.Collections.Generic;