internal override void CollectInputExpressions(List <StatementSyntax> expressions) { var value = ObjectBuilder.Value ?? string.Empty; var type = MyVisualScriptingProxy.GetType(ObjectBuilder.Type); base.CollectInputExpressions(expressions); // First handle special cases as Color and Enums if (type == typeof(Color) || type.IsEnum) { expressions.Add( MySyntaxFactory.LocalVariable( ObjectBuilder.Type, VariableSyntaxName(), SyntaxFactory.MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(ObjectBuilder.Type), SyntaxFactory.IdentifierName(ObjectBuilder.Value) ) ) ); } else if (type == typeof(Vector3D)) { expressions.Add( MySyntaxFactory.LocalVariable(ObjectBuilder.Type, VariableSyntaxName(), MySyntaxFactory.NewVector3D(ObjectBuilder.Value) ) ); } else { // Rest is generic expressions.Add( MySyntaxFactory.LocalVariable( ObjectBuilder.Type, VariableSyntaxName(), MySyntaxFactory.Literal(ObjectBuilder.Type, value)) ); } }
private StatementSyntax GetCorrectAssignmentsExpression() { // Determine Type and create correct assingment var boundVariableNode = Navigator.GetVariable(ObjectBuilder.VariableName); Debug.Assert(boundVariableNode != null, "Missing variable: " + ObjectBuilder.VariableName); var type = MyVisualScriptingProxy.GetType(boundVariableNode.ObjectBuilder.VariableType); if (type == typeof(string)) { if (ObjectBuilder.ValueInputID.NodeID == -1) { return(MySyntaxFactory.VariableAssignmentExpression(ObjectBuilder.VariableName, ObjectBuilder.VariableValue, SyntaxKind.StringLiteralExpression)); } } else if (type == typeof(Vector3D)) { if (ObjectBuilder.ValueInputID.NodeID == -1) { return(MySyntaxFactory.SimpleAssignment(ObjectBuilder.VariableName, MySyntaxFactory.NewVector3D(ObjectBuilder.VariableValue))); } } else if (type == typeof(bool)) { if (ObjectBuilder.ValueInputID.NodeID == -1) { var normalizedValue = MySyntaxFactory.NormalizeBool(ObjectBuilder.VariableValue); var syntaxKind = normalizedValue == "true" ? SyntaxKind.TrueLiteralExpression : SyntaxKind.FalseLiteralExpression; return(MySyntaxFactory.VariableAssignmentExpression( ObjectBuilder.VariableName, ObjectBuilder.VariableValue, syntaxKind)); } } else { if (ObjectBuilder.ValueInputID.NodeID == -1) { return(MySyntaxFactory.VariableAssignmentExpression(ObjectBuilder.VariableName, ObjectBuilder.VariableValue, SyntaxKind.NumericLiteralExpression)); } } return(MySyntaxFactory.SimpleAssignment(ObjectBuilder.VariableName, SyntaxFactory.IdentifierName(m_inputVariableName))); }