本文整理汇总了C#中Microsoft.CodeAnalysis.Scripting.ScriptOptions类的典型用法代码示例。如果您正苦于以下问题:C# ScriptOptions类的具体用法?C# ScriptOptions怎么用?C# ScriptOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ScriptOptions类属于Microsoft.CodeAnalysis.Scripting命名空间,在下文中一共展示了ScriptOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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;
}
示例3: ScriptOptions
private ScriptOptions(ScriptOptions other)
: this(filePath: other.FilePath,
references: other.MetadataReferences,
namespaces: other.Imports,
metadataResolver: other.MetadataResolver,
sourceResolver: other.SourceResolver)
{
}
示例4: WithOptions
internal EvaluationState WithOptions(ScriptOptions options)
{
return new EvaluationState(
ScriptStateOpt,
options,
SourceSearchPaths,
ReferenceSearchPaths,
WorkingDirectory);
}
示例5: ScriptOptions
static ScriptOptions()
{
var paths = ImmutableArray.Create(RuntimeEnvironment.GetRuntimeDirectory());
Default = new ScriptOptions()
.WithReferences(typeof(int).Assembly)
.WithNamespaces("System")
.WithSearchPaths(paths);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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");
}
示例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;
}
示例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);
}
//.........这里部分代码省略.........
示例14: With
internal TaskResult With(ScriptOptions options)
{
return new TaskResult(options, State);
}
示例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;
}