本文整理汇总了C#中Microsoft.CodeAnalysis.Scripting.ScriptOptions类的典型用法代码示例。如果您正苦于以下问题:C# ScriptOptions类的具体用法?C# ScriptOptions怎么用?C# ScriptOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptOptions类属于Microsoft.CodeAnalysis.Scripting命名空间,在下文中一共展示了ScriptOptions类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CommonScriptEngine
protected CommonScriptEngine(IScriptHostFactory scriptHostFactory, ILogProvider logProvider)
{
Guard.AgainstNullArgument("logProvider", logProvider);
ScriptOptions = new ScriptOptions().WithReferences(typeof(Object).Assembly);
_scriptHostFactory = scriptHostFactory;
_log = logProvider.ForCurrentType();
}
开发者ID:scriptcs,项目名称:scriptcs,代码行数:7,代码来源:CommonScriptEngine.cs
示例2: Compile
public IEnumerable<SyntaxTreeDiagnosticResult> Compile(string sourceCode, ScriptOptions options = null)
{
if (String.IsNullOrEmpty(sourceCode))
throw new ArgumentException(nameof(sourceCode));
_previousCompilations.Push(sourceCode);
Script prev = _scriptQueue.Any() ? _scriptQueue.Pop() : null;
var script = CSharpScript.Create(sourceCode, options ?? DefaultOptions).WithPrevious(prev);
ScriptState endState = null;
try { endState = script.RunAsync(); }
catch (CompilationErrorException ex)
{
var compilationError = new SyntaxTreeDiagnosticResult(ex.Message);
_diagnosticMessages.Add(compilationError);
}
_scriptQueue.Push(endState.Script);
if (endState.Variables != null)
{
var res = endState.Variables
.Select(v => new SyntaxTreeDiagnosticResult(-1, -1, v.Name + v.Value) { Name = v.Name, Value = v.Value.ToString() })
.ToList();
_variables.AddRange(res);
}
return _diagnosticMessages.Any() ? _diagnosticMessages : _variables;
}
开发者ID:afrog33k,项目名称:SharpPlayground,代码行数:32,代码来源:RoslynCompilerFacade.cs
示例3: ScriptOptions
private ScriptOptions(ScriptOptions other)
: this(filePath: other.FilePath,
references: other.MetadataReferences,
namespaces: other.Imports,
metadataResolver: other.MetadataResolver,
sourceResolver: other.SourceResolver)
{
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:8,代码来源:ScriptOptions.cs
示例4: WithOptions
internal EvaluationState WithOptions(ScriptOptions options)
{
return new EvaluationState(
ScriptStateOpt,
options,
SourceSearchPaths,
ReferenceSearchPaths,
WorkingDirectory);
}
开发者ID:peter76111,项目名称:roslyn,代码行数:9,代码来源:InteractiveHost.Service.cs
示例5: ScriptOptions
static ScriptOptions()
{
var paths = ImmutableArray.Create(RuntimeEnvironment.GetRuntimeDirectory());
Default = new ScriptOptions()
.WithReferences(typeof(int).Assembly)
.WithNamespaces("System")
.WithSearchPaths(paths);
}
开发者ID:GloryChou,项目名称:roslyn,代码行数:9,代码来源:ScriptOptions.cs
示例6: EvaluationState
internal EvaluationState(
ScriptState<object> scriptState,
ScriptOptions scriptOptions,
ImmutableArray<string> sourceSearchPaths,
ImmutableArray<string> referenceSearchPaths,
string workingDirectory)
{
ScriptStateOpt = scriptState;
ScriptOptions = scriptOptions;
SourceSearchPaths = sourceSearchPaths;
ReferenceSearchPaths = referenceSearchPaths;
WorkingDirectory = workingDirectory;
}
开发者ID:MichalStrehovsky,项目名称:roslyn,代码行数:13,代码来源:InteractiveHost.Service.cs
示例7: Script
internal Script(string code, string path, ScriptOptions options, Type globalsType, ScriptBuilder builder, Script previous)
{
_code = code ?? "";
_path = path ?? "";
_options = options ?? ScriptOptions.Default;
_globalsType = globalsType;
_previous = previous;
if (_previous != null && builder != null && _previous._lazyBuilder != builder)
{
throw new ArgumentException("Incompatible script builder.");
}
_lazyBuilder = builder;
}
开发者ID:noahstein,项目名称:roslyn,代码行数:15,代码来源:Script.cs
示例8: VSScriptRunner
static VSScriptRunner()
{
var VsDir = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
//TODO: find location of Visual Studio installation
//location of package
var path = System.IO.Path.GetDirectoryName(typeof(CSharpScript).Assembly.Location);
var options = ScriptOptions.Default.WithBaseDirectory(path)
.WithSearchPaths(
Path.Combine(VsDir, "PublicAssemblies"),
Path.Combine(VsDir, "PrivateAssemblies"));
options = options.AddReferences(typeof(CSharpScript).Assembly,
typeof(EnvDTE.TextSelection).Assembly,
typeof(EnvDTE.DTE).Assembly);
defaultOptions = options;
}
开发者ID:pgourlain,项目名称:VSREPL,代码行数:15,代码来源:VSScriptRunner.cs
示例9: EvaluationState
internal EvaluationState(
ScriptState<object> scriptStateOpt,
ScriptOptions scriptOptions,
ImmutableArray<string> sourceSearchPaths,
ImmutableArray<string> referenceSearchPaths,
string workingDirectory)
{
Debug.Assert(scriptOptions != null);
Debug.Assert(!sourceSearchPaths.IsDefault);
Debug.Assert(!referenceSearchPaths.IsDefault);
Debug.Assert(workingDirectory != null);
ScriptStateOpt = scriptStateOpt;
ScriptOptions = scriptOptions;
SourceSearchPaths = sourceSearchPaths;
ReferenceSearchPaths = referenceSearchPaths;
WorkingDirectory = workingDirectory;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:18,代码来源:InteractiveHost.Service.cs
示例10: UpdateDefaultOptions
public static void UpdateDefaultOptions(ReplAssembliesReferencesOptionsModel userOptions)
{
var VsDir = Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]);
//TODO: find location of Visual Studio installation
//location of package
var path = System.IO.Path.GetDirectoryName(typeof(CSharpScript).Assembly.Location);
var options = ScriptOptions.Default.WithBaseDirectory(path)
.WithSearchPaths(
Path.Combine(VsDir, "PublicAssemblies"),
Path.Combine(VsDir, "PrivateAssemblies"))
.WithReferences("System", "system.core", "mscorlib", "Microsoft.CSharp","Microsoft.VisualStudio.ComponentModelHost","System.ComponentModel.Composition");
if (userOptions != null)
{
options = options.AddSearchPaths(userOptions.SearchPaths);
options = options.WithReferences(userOptions.References);
options = options.WithNamespaces(userOptions.Namespaces);
defaultOptions = options;
}
}
开发者ID:pgourlain,项目名称:VSREPL,代码行数:19,代码来源:VSScriptRunner.cs
示例11: CreateOptions
private static void CreateOptions()
{
_options = ScriptOptions.Default;
_options = _options.WithReferences(new[]
{
typeof (DateTime).Assembly,
typeof (IEnumerable<>).Assembly,
typeof (Enumerable).Assembly,
typeof (IObjectQuerySerie).Assembly,
typeof (IDb).Assembly,
typeof (ScriptingEngine).Assembly,
typeof (CSharpArgumentInfo).Assembly,
typeof (DynamicObject).Assembly,
typeof (ExpandoObject).Assembly,
typeof (DbExtensions).Assembly
}.Distinct());
_options = _options.WithImports("System", "System.Collections.Generic", "System.Diagnostics", "System.Linq",
"DbInterfaces.Interfaces", "Timeenator.Interfaces", "FileDb.Interfaces", "FileDb", "Timeenator.Impl",
"Timeenator.Impl.Grouping", "Timeenator.Extensions.Grouping", "Timeenator.Extensions.Scientific",
"Timeenator.Extensions.Converting", "Microsoft.CSharp", "System.Dynamic", "DbInterfaces.Interfaces",
"CustomDbExtensions");
}
开发者ID:RF77,项目名称:sharp-tsdb,代码行数:23,代码来源:ScriptingEngine.cs
示例12: Service
public Service()
{
// TODO (tomat): we should share the copied files with the host
_metadataFileProvider = new MetadataShadowCopyProvider(
Path.Combine(Path.GetTempPath(), "InteractiveHostShadow"),
noShadowCopyDirectories: s_systemNoShadowCopyDirectories);
_options = ScriptOptions.Default.WithSearchPaths(DefaultReferenceSearchPaths);
_assemblyLoader = new InteractiveAssemblyLoader(_metadataFileProvider);
_sourceSearchPaths = DefaultSourceSearchPaths;
_formattingOptions = new ObjectFormattingOptions(
memberFormat: MemberDisplayFormat.Inline,
quoteStrings: true,
useHexadecimalNumbers: false,
maxOutputLength: 200,
memberIndentation: " ");
// We want to be sure to delete the shadow-copied files when the process goes away. Frankly
// there's nothing we can do if the process is forcefully quit or goes down in a completely
// uncontrolled manner (like a stack overflow). When the process goes down in a controlled
// manned, we should generally expect this event to be called.
AppDomain.CurrentDomain.ProcessExit += HandleProcessExit;
}
开发者ID:WiiGe,项目名称:roslyn,代码行数:24,代码来源:InteractiveHost.Service.cs
示例13: Execute
public ScriptResult Execute(string code, string[] scriptArgs, AssemblyReferences references, IEnumerable<string> namespaces, ScriptPackSession scriptPackSession)
{
if (scriptPackSession == null)
{
throw new ArgumentNullException("scriptPackSession");
}
if (references == null)
{
throw new ArgumentNullException("references");
}
_log.Debug("Starting to create execution components");
_log.Debug("Creating script host");
var executionReferences = new AssemblyReferences(references.Assemblies, references.Paths);
executionReferences.Union(scriptPackSession.References);
ScriptResult scriptResult;
SessionState<ScriptState> sessionState;
var isFirstExecution = !scriptPackSession.State.ContainsKey(SessionKey);
if (isFirstExecution)
{
var host = _scriptHostFactory.CreateScriptHost(
new ScriptPackManager(scriptPackSession.Contexts), scriptArgs);
ScriptLibraryWrapper.SetHost(host);
_log.Debug("Creating session");
var hostType = host.GetType();
ScriptOptions = ScriptOptions.AddReferences(hostType.Assembly);
var allNamespaces = namespaces.Union(scriptPackSession.Namespaces).Distinct();
foreach (var reference in executionReferences.Paths)
{
_log.DebugFormat("Adding reference to {0}", reference);
ScriptOptions = ScriptOptions.AddReferences(reference);
}
foreach (var assembly in executionReferences.Assemblies)
{
_log.DebugFormat("Adding reference to {0}", assembly.FullName);
ScriptOptions = ScriptOptions.AddReferences(assembly);
}
foreach (var @namespace in allNamespaces)
{
_log.DebugFormat("Importing namespace {0}", @namespace);
ScriptOptions = ScriptOptions.AddNamespaces(@namespace);
}
sessionState = new SessionState<ScriptState> { References = executionReferences, Namespaces = new HashSet<string>(allNamespaces) };
scriptPackSession.State[SessionKey] = sessionState;
scriptResult = Execute(code, host, sessionState);
}
else
{
_log.Debug("Reusing existing session");
sessionState = (SessionState<ScriptState>)scriptPackSession.State[SessionKey];
if (sessionState.References == null)
{
sessionState.References = new AssemblyReferences();
}
if (sessionState.Namespaces == null)
{
sessionState.Namespaces = new HashSet<string>();
}
var newReferences = executionReferences.Except(sessionState.References);
foreach (var reference in newReferences.Paths)
{
_log.DebugFormat("Adding reference to {0}", reference);
ScriptOptions = ScriptOptions.AddReferences(reference);
sessionState.References = sessionState.References.Union(new[] { reference });
}
foreach (var assembly in newReferences.Assemblies)
{
_log.DebugFormat("Adding reference to {0}", assembly.FullName);
ScriptOptions = ScriptOptions.AddReferences(assembly);
sessionState.References = sessionState.References.Union(new[] { assembly });
}
var newNamespaces = namespaces.Except(sessionState.Namespaces);
foreach (var @namespace in newNamespaces)
{
_log.DebugFormat("Importing namespace {0}", @namespace);
ScriptOptions = ScriptOptions.AddNamespaces(@namespace);
sessionState.Namespaces.Add(@namespace);
}
//.........这里部分代码省略.........
开发者ID:scriptcs,项目名称:scriptcs,代码行数:101,代码来源:CommonScriptEngine.cs
示例14: With
internal TaskResult With(ScriptOptions options)
{
return new TaskResult(options, State);
}
开发者ID:noahstein,项目名称:roslyn,代码行数:4,代码来源:InteractiveHost.Service.cs
示例15: Compile
private Script<object> Compile(ScriptState<object> previous, string text, string path, ref ScriptOptions options)
{
Script script = _repl.CreateScript(text).WithOptions(options);
if (previous != null)
{
script = script.WithPrevious(previous.Script);
}
else
{
script = script.WithGlobalsType(_hostObject.GetType());
}
if (path != null)
{
script = script.WithPath(path).WithOptions(script.Options.WithIsInteractive(false));
}
// force build so exception is thrown now if errors are found.
script.Build();
// load all references specified in #r's -- they will all be PE references (may be shadow copied):
foreach (PortableExecutableReference reference in script.GetCompilation().DirectiveReferences)
{
// FullPath refers to the original reference path, not the copy:
LoadReference(reference.FilePath, suppressWarnings: false, addReference: false, options: ref options);
}
return (Script<object>)script;
}
开发者ID:noahstein,项目名称:roslyn,代码行数:30,代码来源:InteractiveHost.Service.cs
示例16: TryCompile
private Script<object> TryCompile(Script previousScript, string code, string path, ScriptOptions options)
{
Script script;
var scriptOptions = options.WithFilePath(path);
if (previousScript != null)
{
script = previousScript.ContinueWith(code, scriptOptions);
}
else
{
script = _replServiceProvider.CreateScript<object>(code, scriptOptions, _globals.GetType(), _assemblyLoader);
}
var diagnostics = script.Compile();
if (diagnostics.HasAnyErrors())
{
DisplayInteractiveErrors(diagnostics, Console.Error);
return null;
}
return (Script<object>)script;
}
开发者ID:XieShuquan,项目名称:roslyn,代码行数:24,代码来源:InteractiveHost.Service.cs
示例17: CommonScriptEngine
protected CommonScriptEngine(IScriptHostFactory scriptHostFactory, ILog logger)
{
ScriptOptions = new ScriptOptions().WithReferences(typeof(ScriptExecutor).Assembly, typeof(Object).Assembly);
_scriptHostFactory = scriptHostFactory;
Logger = logger;
}
开发者ID:modulexcite,项目名称:scriptcs-engines,代码行数:6,代码来源:CommonScriptEngine.cs
示例18: TryCompile
private Script<object> TryCompile(Script previousScript, string code, string path, ScriptOptions options)
{
Script script;
var scriptOptions = options.WithPath(path).WithIsInteractive(path == null);
if (previousScript != null)
{
script = previousScript.ContinueWith(code, scriptOptions);
}
else
{
script = _replServiceProvider.CreateScript<object>(code, scriptOptions, _hostObject.GetType(), _assemblyLoader);
}
// force build so exception is thrown now if errors are found.
try
{
script.Build();
}
catch (CompilationErrorException e)
{
DisplayInteractiveErrors(e.Diagnostics, Console.Error);
return null;
}
// TODO: Do we want to do this?
// Pros: immediate feedback for assemblies that can't be loaded.
// Cons: maybe we won't need them
//foreach (PortableExecutableReference reference in script.GetCompilation().DirectiveReferences)
//{
// LoadReference(reference, suppressWarnings: false);
//}
return (Script<object>)script;
}
开发者ID:MichalStrehovsky,项目名称:roslyn,代码行数:36,代码来源:InteractiveHost.Service.cs
示例19: Service
public Service()
{
_lastTaskGuard = new object();
_lastTask = Task.CompletedTask;
_scriptOptions = ScriptOptions.Default;
ObjectExtensions.Dumped += OnDumped;
}
开发者ID:mjheitland,项目名称:TableTweaker,代码行数:8,代码来源:ExecutionHost.cs
示例20: ExecuteScript
protected abstract ScriptState ExecuteScript(string text, ScriptOptions options);
开发者ID:modulexcite,项目名称:FiddlerScriptCSharp,代码行数:1,代码来源:FiddlerRoslynScriptBase.cs
注:本文中的Microsoft.CodeAnalysis.Scripting.ScriptOptions类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论