Ejemplo n.º 1
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
                       ));
        }