Skip to content

Commit

Permalink
now do not generate for props that do not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatandrei committed Apr 25, 2020
1 parent 47fab09 commit e2530fd
Showing 1 changed file with 8 additions and 2 deletions.
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -95,11 +96,16 @@ public string GenerateDefinitionString(Type type)
/// <returns></returns>
public string GenerateJSstring(Type type)
{
bool isArray = type.IsSubclassOf(typeof(IEnumerable));
string filterNull = (isArray) ? ".filter(it=>it !=null)" : "";
var objectProperties =
string.Join( Environment.NewLine,
type.GetProperties().Select(prop =>
$"objPropString.push('\"{prop.Name}\":'+Blockly.JavaScript.valueToCode(block, \"val_{prop.Name}\", Blockly.JavaScript.ORDER_ATOMIC));")
$"let val{prop.Name} = Blockly.JavaScript.valueToCode(block, \"val_{prop.Name}\", Blockly.JavaScript.ORDER_ATOMIC);"+
$"if(val{prop.Name} != ''){{" +
$"val{prop.Name} = val{prop.Name}.filter(it=>it != null);"+
$"objPropString.push('\"{prop.Name}\":'+val{prop.Name});"+
$"}}")
);

var strJS = $@" Blockly.JavaScript['{type.TranslateToNewTypeName()}'] = function(block) {{
Expand Down

0 comments on commit e2530fd

Please sign in to comment.