当前位置: 首页>>代码示例>>C#>>正文


C# ScriptOptions类代码示例

本文整理汇总了C#中ScriptOptions的典型用法代码示例。如果您正苦于以下问题:C# ScriptOptions类的具体用法?C# ScriptOptions怎么用?C# ScriptOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ScriptOptions类属于命名空间,在下文中一共展示了ScriptOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: JavaScript

        public static void JavaScript(Page page, string script, ScriptOptions options)
        {
            if (page == null) throw new ArgumentNullException("page");

            if (page.Items[script] == null)
            {
                PlaceHolder holder = GetPlaceHolder(page);

                if (Is(options, ScriptOptions.Include))
                {
                    AddScriptInclude(page, script, holder, Is(options, ScriptOptions.Prioritize));
                }
                else if (Is(options, ScriptOptions.None))
                {
                    holder.Page.Items[script] = AddString(script, holder, Is(options, ScriptOptions.Prioritize));
                }
                else
                {
                    Script scriptHolder = GetScriptHolder(page);
                    if (Is(options, ScriptOptions.ScriptTags))
                    {
                        holder.Page.Items[script] = AddString(script + Environment.NewLine, scriptHolder, Is(options, ScriptOptions.Prioritize));
                    }
                    else if (Is(options, ScriptOptions.DocumentReady))
                    {
                        JQuery(page);
                        holder.Page.Items[script] = AddString(EmbedDocumentReady(script) + Environment.NewLine, scriptHolder, Is(options, ScriptOptions.Prioritize));
                    }
                }
            }
        }
开发者ID:spmason,项目名称:n2cms,代码行数:31,代码来源:Register.cs

示例2: JavaScript

        /// <summary>Registers a script block on a page.</summary>
        /// <param name="page">The page onto which to added the script.</param>
        /// <param name="script">The script to add.</param>
        /// <param name="position">Where to add the script.</param>
        /// <param name="options">Script registration options.</param>
        public static void JavaScript(Page page, string script, ScriptPosition position, ScriptOptions options)
        {
            if (page == null) throw new ArgumentNullException("page");

            if (position == ScriptPosition.Header)
            {
                JavaScript(page, script, options);
            }
            else if (position == ScriptPosition.Bottom)
            {
                string key = script.GetHashCode().ToString();
                if (Is(options, ScriptOptions.None))
                    page.ClientScript.RegisterClientScriptBlock(typeof (Register), key, script);
                else if (Is(options, ScriptOptions.ScriptTags))
                    page.ClientScript.RegisterClientScriptBlock(typeof (Register), key, script, true);
                else if (Is(options, ScriptOptions.DocumentReady))
                {
                    JQuery(page);
                    page.ClientScript.RegisterClientScriptBlock(typeof (Register), key, EmbedDocumentReady(script), true);
                }
                else if (Is(options, ScriptOptions.Include))
                    page.ClientScript.RegisterClientScriptInclude(key, page.Engine().ManagementPaths.ResolveResourceUrl(script));
                else
                    throw new ArgumentException("options");
            }
            else
                throw new ArgumentException("position");
        }
开发者ID:sergheizagaiciuc,项目名称:n2cms,代码行数:33,代码来源:Register.cs

示例3: JavaScript

        /// <summary>Registers a script block on a page.</summary>
        /// <param name="page">The page onto which to added the script.</param>
        /// <param name="script">The script to add.</param>
        /// <param name="position">Where to add the script.</param>
        /// <param name="options">Script registration options.</param>
        public static void JavaScript(this Page page, string script, ScriptPosition position, ScriptOptions options)
        {
            if (page == null) throw new ArgumentNullException("page");

            if (position == ScriptPosition.Header)
            {
                JavaScript(page, script, options);
            }
            else if (position == ScriptPosition.Bottom)
            {
                string key = script.GetHashCode().ToString();
                if (options.Is(ScriptOptions.None))
                    page.ClientScript.RegisterStartupScript(typeof(Register), key, script);
                else if (options.Is(ScriptOptions.ScriptTags))
                    page.ClientScript.RegisterStartupScript(typeof(Register), key, script, true);
                else if (options.Is(ScriptOptions.DocumentReady))
                {
                    page.JQuery();
                    page.ClientScript.RegisterStartupScript(typeof(Register), key, EmbedDocumentReady(script), true);
                }
                else if (options.Is(ScriptOptions.Include))
                    page.ClientScript.RegisterClientScriptInclude(key, Url.ResolveTokens(script));
                else
                    throw new ArgumentException("options");
            }
            else
                throw new ArgumentException("position");
        }
开发者ID:pauldotknopf,项目名称:Noodle,代码行数:33,代码来源:Register.cs

示例4: GenerateJavaScriptOptionsDoesAlwaysQuotingObjecLiteralKeys

        public void GenerateJavaScriptOptionsDoesAlwaysQuotingObjecLiteralKeys()
        {
            var literal = JS.Object(new {name = "Dave", function = "Developer"});

            var without = new ScriptOptions {AlwaysQuoteObjectLiteralKeys = false, PreferredQuoteChar = '"'};
            var with = new ScriptOptions {AlwaysQuoteObjectLiteralKeys = true, PreferredQuoteChar = '"'};

            Assert.AreEqual("{name:\"Dave\",function:\"Developer\"};", literal.ToString(true, without, false));
            Assert.AreEqual("{\"name\":\"Dave\",\"function\":\"Developer\"};", literal.ToString(true, with, false));
        }
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:10,代码来源:GenerateJavaScriptOptionsTests.cs

示例5: GenerateJavaScriptOptionsCanBeSet

        public void GenerateJavaScriptOptionsCanBeSet()
        {
            ScriptOptions options = new ScriptOptions();

            options.PreferredQuoteChar = '\'';

            Assert.AreEqual('\'', options.PreferredQuoteChar);

            Expect.Throw<ArgumentException>(
                "The preferred quote char can only be one of the allowed quote chars.\r\nParameter name: value",
                () => options.PreferredQuoteChar = '@');
        }
开发者ID:DaveVdE,项目名称:adamjsgenerator,代码行数:12,代码来源:GenerateJavaScriptOptionsTests.cs

示例6: RunScript

        private int RunScript(ScriptOptions options, string code, ErrorLogger errorLogger, CancellationToken cancellationToken)
        {
            var globals = new CommandLineScriptGlobals(_console.Out, _objectFormatter);
            globals.Args.AddRange(_compiler.Arguments.ScriptArguments);

            var script = Script.CreateInitialScript<object>(_scriptCompiler, code, options, globals.GetType(), assemblyLoaderOpt: null);
            try
            {
                script.RunAsync(globals, cancellationToken).Wait();

                // TODO: use the return value of the script https://github.com/dotnet/roslyn/issues/5773
                return CommonCompiler.Succeeded;
            }
            catch (CompilationErrorException e)
            {
                _compiler.ReportErrors(e.Diagnostics, _console.Out, errorLogger);
                return CommonCompiler.Failed;
            }
        }
开发者ID:hcn0843,项目名称:roslyn,代码行数:19,代码来源:CommandLineRunner.cs

示例7: Is

 private static bool Is(this ScriptOptions options, ScriptOptions expectedOption)
 {
     return (options & expectedOption) == expectedOption;
 }
开发者ID:jackiezhang926,项目名称:n2cms,代码行数:4,代码来源:Register.cs

示例8: JavaScript

 public ResourcesHelper JavaScript(string script, ScriptOptions options)
 {
     Writer.Write(N2.Resources.Register.JavaScript(ViewData, script, options));
     return this;
 }
开发者ID:Jobu,项目名称:n2cms,代码行数:5,代码来源:ResourcesExtensions.cs

示例9: TryBuildAndRun

        private bool TryBuildAndRun(Script<object> newScript, InteractiveScriptGlobals globals, ref ScriptState<object> state, ref ScriptOptions options, CancellationToken cancellationToken)
        {
            var diagnostics = newScript.Compile(cancellationToken);
            DisplayDiagnostics(diagnostics);
            if (diagnostics.HasAnyErrors())
            {
                return false;
            }

            try
            {
                var task = (state == null) ?
                    newScript.RunAsync(globals, cancellationToken) :
                    newScript.ContinueAsync(state, cancellationToken);

                state = task.GetAwaiter().GetResult();
            }
            catch (FileLoadException e) when (e.InnerException is InteractiveAssemblyLoaderException)
            {
                var oldColor = _console.ForegroundColor;
                try
                {
                    _console.ForegroundColor = ConsoleColor.Red;
                    _console.Out.WriteLine(e.InnerException.Message);
                }
                finally
                {
                    _console.ForegroundColor = oldColor;
                }

                return false;
            }
            catch (Exception e)
            {
                DisplayException(e);
                return false;
            }

            options = UpdateOptions(options, globals);

            return true;
        }
开发者ID:Ryujose,项目名称:roslyn,代码行数:42,代码来源:CommandLineRunner.cs

示例10: JavaScript

		public static string JavaScript(ICollection<string> stateCollection, string script, ScriptOptions options)
		{
			const string scriptFormat = "<script type=\"text/javascript\">//<![CDATA[\n{0}//]]></script>";

			if (IsRegistered(stateCollection, script))
				return null;

			RegisterResource(stateCollection, script);

			if (options == ScriptOptions.Include)
				return JavaScript(stateCollection, script);
			if (options == ScriptOptions.None)
				return script;
			if (options == ScriptOptions.ScriptTags)
				return String.Format(scriptFormat, script);
			if (options == ScriptOptions.DocumentReady)
				return String.Format(scriptFormat, EmbedDocumentReady(script));

			throw new NotSupportedException(options + " not supported");
		}
开发者ID:nicklv,项目名称:n2cms,代码行数:20,代码来源:Register.cs

示例11: JavaScript

		public static void JavaScript(this Page page, string script, ScriptOptions options)
		{
			if (page == null) return;

			if (page.Items[script] == null)
			{
				PlaceHolder holder = GetPlaceHolder(page);

				if (options.Is(ScriptOptions.Include))
				{
					AddScriptInclude(page, script, holder, options.Is(ScriptOptions.Prioritize));
				}
				else if (options.Is(ScriptOptions.None))
				{
					holder.Page.Items[script] = AddString(holder, script, options.Is(ScriptOptions.Prioritize));
				}
				else
				{
					Script scriptHolder = GetScriptHolder(page);
					if (options.Is(ScriptOptions.ScriptTags))
					{
						holder.Page.Items[script] = AddString(scriptHolder, script + Environment.NewLine, Is(options, ScriptOptions.Prioritize));
					}
					else if (options.Is(ScriptOptions.DocumentReady))
					{
						JQuery(page);
						holder.Page.Items[script] = AddString(scriptHolder, EmbedDocumentReady(script) + Environment.NewLine, options.Is(ScriptOptions.Prioritize));
					}
				}
			}
		}
开发者ID:n2cms,项目名称:n2cms,代码行数:31,代码来源:Register.cs

示例12: BuildAndRun

        private void BuildAndRun(Script<object> newScript, InteractiveScriptGlobals globals, ref ScriptState<object> state, ref ScriptOptions options, bool displayResult, CancellationToken cancellationToken)
        {
            var diagnostics = newScript.Compile(cancellationToken);
            DisplayDiagnostics(diagnostics);
            if (diagnostics.HasAnyErrors())
            {
                return;
            }

            var task = (state == null) ?
                newScript.RunAsync(globals, catchException: e => true, cancellationToken: cancellationToken) :
                newScript.RunFromAsync(state, catchException: e => true, cancellationToken: cancellationToken);

            state = task.GetAwaiter().GetResult();
            if (state.Exception != null)
            {
                DisplayException(state.Exception);
            }
            else if (displayResult && newScript.HasReturnValue())
            {
                globals.Print(state.ReturnValue);
            }

            options = UpdateOptions(options, globals);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:25,代码来源:CommandLineRunner.cs

示例13: AddScripts

 private void AddScripts(IEnumerable<string> names, ScriptOptions options)
 {
     if (null != names)
     {
         foreach (var script in names)
         {
             Converter.AddScript(script, options);
         }
     }
 }
开发者ID:thomas13335,项目名称:wpf2html5,代码行数:10,代码来源:ConverterModel.cs

示例14: RunInteractiveLoop

        private void RunInteractiveLoop(ScriptOptions options, CancellationToken cancellationToken)
        {
            var globals = new InteractiveScriptGlobals(_console.Out, _objectFormatter);
            globals.Args.AddRange(_compiler.Arguments.ScriptArguments);

            ScriptState <object> state = null;

            while (true)
            {
                _console.Out.Write("> ");
                var input = new StringBuilder();
                string line;
                bool cancelSubmission = false;

                while (true)
                {
                    line = _console.In.ReadLine();
                    if (line == null)
                    {
                        if (input.Length == 0)
                        {
                            return;
                        }

                        cancelSubmission = true;
                        break;
                    }

                    input.AppendLine(line);

                    var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), cancellationToken);
                    if (_scriptCompiler.IsCompleteSubmission(tree))
                    {
                        break;
                    }

                    _console.Out.Write(". ");
                }

                if (cancelSubmission)
                {
                    continue;
                }

                string code = input.ToString();

                Script<object> newScript;
                if (state == null)
                {
                    newScript = Script.CreateInitialScript<object>(_scriptCompiler, code, options, globals.GetType(), assemblyLoaderOpt: null);
                }
                else
                {
                    newScript = state.Script.ContinueWith(code, options);
                }

                var newCompilation = newScript.GetCompilation();

                try
                {
                    newScript.Build(cancellationToken);

                    // display warnings:
                    DisplayDiagnostics(newCompilation.GetDiagnostics(cancellationToken).Where(d => d.Severity == DiagnosticSeverity.Warning));
                }
                catch (CompilationErrorException e)
                {
                    DisplayDiagnostics(e.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error || d.Severity == DiagnosticSeverity.Warning));
                    continue;
                }

                try
                {
                    var task = (state == null) ?
                        newScript.RunAsync(globals, cancellationToken) :
                        newScript.ContinueAsync(state, cancellationToken);

                    state = task.GetAwaiter().GetResult();
                }
                catch (Exception e)
                {
                    DisplayException(e);
                    continue;
                }

                bool hasValue;
                ITypeSymbol resultType = newCompilation.GetSubmissionResultType(out hasValue);
                if (hasValue)
                {
                    if (resultType != null && resultType.SpecialType == SpecialType.System_Void)
                    {
                        _console.Out.WriteLine(_objectFormatter.VoidDisplayString);
                    }
                    else
                    {
                        globals.Print(state.ReturnValue);
                    }
                }
            }
        }
开发者ID:e42s,项目名称:roslyn,代码行数:100,代码来源:CommandLineRunner.cs

示例15: AddScript

        public void AddScript(string filename, ScriptOptions options)
        {
            switch(options)
            {
                case ScriptOptions.Framework:
                    _frameworkscripts.Add(filename);
                    break;

                case ScriptOptions.Before:
                    _scriptsbefore.Add(filename);
                    break;

                case ScriptOptions.After:
                    _scriptsafter.Add(filename);
                    break;

                default:
                    throw new ArgumentException("invalid script option specified.");
            }
        }
开发者ID:thomas13335,项目名称:wpf2html5,代码行数:20,代码来源:WpfToHtmlConverter.cs


注:本文中的ScriptOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。