internal override void CollectInputExpressions(List <StatementSyntax> expressions) { base.CollectInputExpressions(expressions); var entryType = MyVisualScriptingProxy.GetType(ObjectBuilder.Type); var listType = typeof(List <>).MakeGenericType(entryType); var separatedList = new List <SyntaxNodeOrToken>(); // Create source of arguments for array creation syntax for (var index = 0; index < ObjectBuilder.DefaultEntries.Count; index++) { var entry = ObjectBuilder.DefaultEntries[index]; var literal = MySyntaxFactory.Literal(ObjectBuilder.Type, entry); separatedList.Add(literal); if (index < ObjectBuilder.DefaultEntries.Count - 1) { separatedList.Add(SyntaxFactory.Token(SyntaxKind.CommaToken)); } } // Syntax of "new Type[]{arg0, arg1, ...}" ArrayCreationExpressionSyntax arrayCreationSyntax = null; if (separatedList.Count > 0) { arrayCreationSyntax = SyntaxFactory.ArrayCreationExpression( SyntaxFactory.ArrayType( SyntaxFactory.IdentifierName(ObjectBuilder.Type), SyntaxFactory.SingletonList( SyntaxFactory.ArrayRankSpecifier( SyntaxFactory.SingletonSeparatedList <ExpressionSyntax>( SyntaxFactory.OmittedArraySizeExpression() ) ) ) ), SyntaxFactory.InitializerExpression( SyntaxKind.ArrayInitializerExpression, SyntaxFactory.SeparatedList <ExpressionSyntax>( separatedList ) ) ); } // Syntax of new List<Type>(arrayCreationSyntax); var listCreationSyntax = MySyntaxFactory.GenericObjectCreation(listType, arrayCreationSyntax == null ? null : new[] { arrayCreationSyntax }); var localVariableSyntax = MySyntaxFactory.LocalVariable(listType, VariableSyntaxName(), listCreationSyntax); expressions.Add(localVariableSyntax); }
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 )); }