Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Predefined List in Code Generation extension #23

Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a6fad7e
Added handling for predefined lists for code generation of TextField
devlife Mar 5, 2021
a546a6d
Reverted some string formatting
devlife Mar 5, 2021
3448418
Check for name and value properties
devlife Mar 6, 2021
8b1ac54
Spacing
devlife Mar 8, 2021
b979035
Updated formatting
devlife Apr 8, 2021
52c07ff
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Apr 9, 2021
aeae0f1
Replaced tabs with spaces
devlife Apr 19, 2021
4712eba
Merge branch 'extension/code-generation/add-predefined-list-handling'…
devlife Apr 19, 2021
8da317e
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Apr 20, 2021
4de0065
Merge branch 'Lombiq:dev' into extension/code-generation/add-predefin…
devlife Mar 5, 2022
b8c7555
Fixed up formatting
devlife Mar 5, 2022
af195a0
Removed NuGet.config
devlife Mar 5, 2022
480e111
Update to use ContainsOrdinalIgnoreCase
devlife Mar 7, 2022
a3b98fc
Rename parameter
devlife Mar 8, 2022
926bcc6
Update error message
devlife Mar 8, 2022
6cc87f4
Made array init format properties on separate lines
devlife Mar 8, 2022
af907dd
Fix formatting
devlife Mar 8, 2022
49cff4c
Remove extra closing brace
devlife Mar 8, 2022
5103ada
Updated formatting and removed @ symbol
devlife Mar 8, 2022
372c1f2
Fix string array formatting
devlife Mar 8, 2022
fd3a307
Add missing comma
devlife Mar 8, 2022
74e462e
Update for code analyzer fixes
devlife Mar 8, 2022
c985db2
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Mar 8, 2022
b62ee3a
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Mar 8, 2022
24d2e11
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Mar 8, 2022
1016044
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Mar 8, 2022
78f895d
Update Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
devlife Mar 8, 2022
9b6be42
Renamed `format` to `indentation`
devlife Mar 9, 2022
18ce507
Merge branch 'extension/code-generation/add-predefined-list-handling'…
devlife Mar 9, 2022
70942a4
Rename variable
devlife Mar 9, 2022
dd7160f
Converted string.Join to use string ctor
devlife Mar 9, 2022
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
17 changes: 11 additions & 6 deletions Extensions/CodeGeneration/CodeGenerationDisplayDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private void GenerateCodeForPartsWithFields(
}
}

private string ConvertJToken(JToken jToken)
private string ConvertJToken(JToken jToken, int indentationDepth)
devlife marked this conversation as resolved.
Show resolved Hide resolved
{
switch (jToken)
{
Expand All @@ -133,16 +133,18 @@ private string ConvertJToken(JToken jToken)
};

case JArray jArray:
var token = string.Join(", ", jArray.Select(ConvertJToken));
var format = token.Contains("ListValueOption") ? "\n " : string.Empty;

var token = string.Join(", ", jArray.Select(a => ConvertJToken(a, indentationDepth * 2)));
devlife marked this conversation as resolved.
Show resolved Hide resolved
var format = token.Contains("ListValueOption", StringComparison.InvariantCulture)
? $"\n{string.Join(string.Empty, Enumerable.Repeat(" ", (int)(indentationDepth * 1.5)))}"
Piedone marked this conversation as resolved.
Show resolved Hide resolved
: string.Empty;

return $"new[] {format}{{ {string.Join(", ", token)} {format}}}";

case JObject jObject:
var indentation = string.Join(string.Empty, Enumerable.Repeat(" ", indentationDepth));
if (jObject["name"] != null && jObject["value"] != null)
{
return $"\n new ListValueOption {{ Name = \"{jObject["name"]}\", Value = \"{jObject["value"]}\" }}";
return $"\n{indentation}new ListValueOption {{ Name = \"{jObject["name"]}\", Value = \"{jObject["value"]}\" }}";
Piedone marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand All @@ -161,8 +163,10 @@ private void AddSettingsWithout<T>(StringBuilder codeBuilder, JObject settings,

var filteredSettings = ((IEnumerable<KeyValuePair<string, JToken>>)settings)
.Where(setting => setting.Key != typeof(T).Name);

foreach (var setting in filteredSettings)
{

var properties = setting.Value.Where(property => property is JProperty).Cast<JProperty>().ToArray();

if (properties.Length == 0) continue;
Expand All @@ -175,7 +179,8 @@ private void AddSettingsWithout<T>(StringBuilder codeBuilder, JObject settings,
for (int i = 0; i < properties.Length; i++)
{
var property = properties[i];
var propertyValue = ConvertJToken(property.Value);

var propertyValue = ConvertJToken(property.Value, indentationDepth);

if (propertyValue == null)
{
Expand Down