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)));
        }
Example #2
0
        public ExpressionStatementSyntax CreateInitializationSyntax()
        {
            if (m_variableType.IsGenericType)
            {
                var objectCreationSyntax         = MySyntaxFactory.GenericObjectCreation(m_variableType);
                var variableAssignmentExpression = MySyntaxFactory.VariableAssignment(ObjectBuilder.VariableName, objectCreationSyntax);
                return(SyntaxFactory.ExpressionStatement(variableAssignmentExpression));
            }

            if (m_variableType == typeof(Vector3D))
            {
                return(MySyntaxFactory.VectorAssignmentExpression(
                           ObjectBuilder.VariableName, ObjectBuilder.VariableType,
                           ObjectBuilder.Vector.X, ObjectBuilder.Vector.Y, ObjectBuilder.Vector.Z
                           ));
            }

            if (m_variableType == typeof(string))
            {
                return(MySyntaxFactory.VariableAssignmentExpression(
                           ObjectBuilder.VariableName, ObjectBuilder.VariableValue, SyntaxKind.StringLiteralExpression
                           ));
            }

            if (m_variableType == typeof(bool))
            {
                var normalizedValue = MySyntaxFactory.NormalizeBool(ObjectBuilder.VariableValue);
                var syntaxKind      = normalizedValue == "true"
                    ? SyntaxKind.TrueLiteralExpression
                    : SyntaxKind.FalseLiteralExpression;
                return(MySyntaxFactory.VariableAssignmentExpression(
                           ObjectBuilder.VariableName, ObjectBuilder.VariableValue, syntaxKind));
            }

            return(MySyntaxFactory.VariableAssignmentExpression(
                       ObjectBuilder.VariableName, ObjectBuilder.VariableValue, SyntaxKind.NumericLiteralExpression
                       ));
        }