array inside class · ignatandrei/NETCoreBlockly@be39947 · GitHub
Skip to content

Commit be39947

Browse files
committed
array inside class
1 parent cfbf44b commit be39947

7 files changed

Lines changed: 112 additions & 3 deletions

File tree

‎azure-pipelines.yml‎

Lines changed: 1 addition & 1 deletion

‎src/NetCore2Blockly/NetCore2Blockly/ExtensionMethods/ActionListExtensions.cs‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,34 @@ private static TypeArgumentBase[] recursive(TypeArgumentBase[] types)
1515
{
1616
var ids = types.Select(it => it.id).Distinct().ToArray();
1717

18-
var propsExtra =
18+
var allProps =
1919
types.SelectMany(it => it.GetProperties())
2020
.Where(it => it != null && it.PropertyType != null)
21-
.Where(it => it.PropertyType.TranslateToBlocklyType() == null)
2221
.Where(type => type.PropertyType.id != null)
22+
.ToArray();
23+
// find arrays;
24+
var propsExtra = allProps
25+
.Where(it => it.PropertyType.TranslateToBlocklyType() == null)
2326
.Select(it => it.PropertyType)
2427
.Where(type => !ids.Contains(type.id))
2528
.ToArray();
2629

30+
var arrayProps = allProps
31+
.Where(it => it.IsArray)
32+
.Where(it => (it as PropertyCSharp) != null)
33+
.Select(it => it as PropertyCSharp)
34+
.Select(it=>it.PropertyType as TypeToGenerateFromCSharp)
35+
.Where(it =>it != null)
36+
.Select(it=> it.GetUnderlyingArrayType())
37+
.Where(it => it != null)
38+
.Where(it => it.TranslateToBlocklyType() == null)
39+
.Where(type => !ids.Contains(type.id))
40+
.ToArray();
41+
42+
if (arrayProps.Length > 0)
43+
{
44+
propsExtra = propsExtra.Union(arrayProps).ToArray();
45+
}
2746
if (propsExtra.Length == 0)
2847
return types;
2948

‎src/NetCore2Blockly/NetCore2Blockly/TypeToGenerateFromCSharp.cs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ public override string TypeNameForBlockly
9595
public override string FullName => t.FullName;
9696

9797
public override bool IsValueType => t.IsValueType;
98+
99+
public TypeToGenerateFromCSharp GetUnderlyingArrayType()
100+
{
101+
if (!t.IsArray)
102+
return null;
103+
return new TypeToGenerateFromCSharp( t.GetElementType());
104+
105+
}
98106
}
99107

100108
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace TestBlocklyHtml.Controllers
2+
{
3+
public class DepartmentX
4+
{
5+
public string Name { get; set; }
6+
public EmployeeX[] Employees { get; set; }
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace TestBlocklyHtml.Controllers
2+
{
3+
public class EmployeeX
4+
{
5+
public string Name { get; set; }
6+
}
7+
}

‎src/NetCore2Blockly/TestBlocklyHtml/Controllers/VariousTestsController.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public VariousTestsController()
3333
{
3434
}
3535

36+
[HttpPost]
37+
public string TestArray(DepartmentX id)
38+
{
39+
return $"this is {id?.Name} employees:" + id?.Employees?.Length;
40+
}
3641

3742
[HttpPost]
3843
public string TestInsideVariable(WithInsideClass id)

‎src/NetCore2Blockly/TestBlocklyHtml/wwwroot/doNotCopy/testing.js‎

Lines changed: 62 additions & 0 deletions

0 commit comments

Comments
 (0)