Exemple #1
0
        /// <summary>
        /// Add parameters to the script statement.
        /// </summary>
        /// <param name="scriptStatement">
        /// The script statement.
        /// </param>
        /// <param name="allowStatement">
        /// The allow statement.
        /// </param>
        /// <param name="parameters">
        /// The parameters.
        /// </param>
        private static void AddParameters([NotNull] this IScriptStatementContext scriptStatement, bool allowStatement, [NotNull] IEnumerable <object> parameters)
        {
            if (parameters.Any())
            {
                parameters.ForEachFirst(
                    (param, isFirst) =>
                {
                    if (!isFirst)
                    {
                        scriptStatement.Add(",");
                    }

                    if (allowStatement && param.HasInterface <IScriptStatementContext>())
                    {
                        scriptStatement.Add(
                            param.ToClass <IScriptStatementContext>().ScriptStatement.Build(scriptStatement.ScriptBuilder));
                    }
                    else if (param is string)
                    {
                        scriptStatement.AddString(param.ToString());
                    }
                    else
                    {
                        scriptStatement.Add(param.ToString());
                    }
                });
            }
        }
Exemple #2
0
        public static IScriptStatementContext Add(
            [NotNull] this IScriptStatementContext scriptStatement, [NotNull] IScriptStatement addStatement)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(addStatement, "addStatement");

            return(scriptStatement.Add(addStatement.Build(scriptStatement.ScriptBuilder)));
        }
Exemple #3
0
        public static IScriptStatementContext AddFormat(
            [NotNull] this IScriptStatementContext scriptStatement, [NotNull] string js, [NotNull] params object[] args)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(js, "js");
            CodeContracts.ArgumentNotNull(args, "args");

            scriptStatement.Add(js.FormatWith(args));

            return(scriptStatement);
        }
Exemple #4
0
        public static IScriptStatementContext AddFunc(
            [NotNull] this IScriptStatementContext scriptStatement, [NotNull] Action <IScriptFunctionContext> buildFunction)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(buildFunction, "buildFunction");

            var function = scriptStatement.ScriptBuilder.CreateFunction(false);

            buildFunction(function);

            return(scriptStatement.Add(function.Build()));
        }
Exemple #5
0
        public static IScriptStatementContext AddCall(
            [NotNull] this IScriptStatementContext scriptStatement,
            [NotNull] string functionName,
            [NotNull] params object[] parameters)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(functionName, "functionName");
            CodeContracts.ArgumentNotNull(parameters, "parameters");

            scriptStatement.AddFormat("{0}(", functionName);

            AddParameters(scriptStatement, true, parameters);

            scriptStatement.Add(")");

            return(scriptStatement);
        }
Exemple #6
0
        public static IScriptStatementContext AddArray(
            [NotNull] this IScriptStatementContext scriptStatement,
            [NotNull] string arrayName,
            [NotNull] params object[] parameters)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");
            CodeContracts.ArgumentNotNull(arrayName, "arrayName");

            scriptStatement.AddLine();
            scriptStatement.AddFormat("var {0} = Array(", arrayName);

            AddParameters(scriptStatement, false, parameters);

            scriptStatement.Add(");");

            scriptStatement.AddLine();

            return(scriptStatement);
        }
Exemple #7
0
        public static IScriptStatementContext End([NotNull] this IScriptStatementContext scriptStatement)
        {
            CodeContracts.ArgumentNotNull(scriptStatement, "scriptStatement");

            return(scriptStatement.Add(";\r\n"));
        }