change - forcing dependency namespace ("System.Collections.Generic") to be added for list and dictionary in cases where common namespace addition(CSharpRenderer.emitUsings) was skipped
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.
Example with dictionary
command: echo '{ "name": "David","keyval":{"1":{"prop1":1},"2":{"prop1":1},"3":{"prop1":3}} }' | script/quicktype -l csharp --features just-types
output:
namespace QuickType
{
public partial class TopLevel
{
public string Name { get; set; }
public Dictionary<string, Keyval> Keyval { get; set; }
}
public partial class Keyval
{
public long Prop1 { get; set; }
}
}
Example with array as list
command: echo '{ "name": "David","arr":[1,2,3] }' | script/quicktype -l csharp --features just-types --array-type list
output:
namespace QuickType
{
public partial class TopLevel
{
public string Name { get; set; }
public List<long> Arr { get; set; }
}
}
New Behaviour / Output
with new change using System.Collections.Generic gets added inside name space before class definition when required
Example with dictionary
command: echo '{ "name": "David","keyval":{"1":{"prop1":1},"2":{"prop1":1},"3":{"prop1":3}} }' | script/quicktype -l csharp --features just-types
output:
namespace QuickType
{
using System.Collections.Generic;
public partial class TopLevel
{
public string Name { get; set; }
public Dictionary<string, Keyval> Keyval { get; set; }
}
public partial class Keyval
{
public long Prop1 { get; set; }
}
}
Example with array as list
command: echo '{ "name": "David","arr":[1,2,3] }' | script/quicktype -l csharp --features just-types --array-type list
output:
namespace QuickType
{
using System.Collections.Generic;
public partial class TopLevel
{
public string Name { get; set; }
public List<long> Arr { get; set; }
}
}
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;
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
https://github.com/glideapps/quicktype/issues/2523
Motivation and Context
https://github.com/glideapps/quicktype/issues/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.
Example with dictionary command:
echo '{ "name": "David","keyval":{"1":{"prop1":1},"2":{"prop1":1},"3":{"prop1":3}} }' | script/quicktype -l csharp --features just-types
output:Example with array as list 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 requiredExample with dictionary command:
echo '{ "name": "David","keyval":{"1":{"prop1":1},"2":{"prop1":1},"3":{"prop1":3}} }' | script/quicktype -l csharp --features just-types
output:Example with array as list 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;