本文整理汇总了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));
}
}
}
}
示例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");
}
示例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");
}
示例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));
}
示例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 = '@');
}
示例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;
}
}
示例7: Is
private static bool Is(this ScriptOptions options, ScriptOptions expectedOption)
{
return (options & expectedOption) == expectedOption;
}
示例8: JavaScript
public ResourcesHelper JavaScript(string script, ScriptOptions options)
{
Writer.Write(N2.Resources.Register.JavaScript(ViewData, script, options));
return this;
}
示例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;
}
示例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");
}
示例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));
}
}
}
}
示例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);
}
示例13: AddScripts
private void AddScripts(IEnumerable<string> names, ScriptOptions options)
{
if (null != names)
{
foreach (var script in names)
{
Converter.AddScript(script, options);
}
}
}
示例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);
}
}
}
}
示例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.");
}
}