Helper class to do source reference resolver for files.
Inheritance: Microsoft.CodeAnalysis.SourceReferenceResolver
示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InteractiveExecution"/> class.
        /// </summary>
        public InteractiveExecution()
        {
            var scriptOptions = ScriptOptions.Default.WithImports(ScriptCompiler.DefaultUsings).AddReferences(ScriptCompiler.DefaultAssemblyReferences);

            var originalSourceResolver   = scriptOptions.SourceResolver;
            var originalMetadataResolver = scriptOptions.MetadataResolver;

            metadataResolver = new ScriptExecution.MetadataResolver(originalMetadataResolver);
            sourceResolver   = new ScriptExecution.SourceResolver(originalSourceResolver);
            scriptOptions    = scriptOptions.WithMetadataResolver(metadataResolver);
            scriptOptions    = scriptOptions.WithSourceResolver(sourceResolver);

            scriptState                       = CSharpScript.RunAsync(string.Join("\n", ScriptCompiler.DefaultAliases.Select(s => $"using {s};")), scriptOptions, scriptBase).Result;
            scriptBase.ObjectWriter           = new DefaultObjectWriter();
            scriptBase._InternalObjectWriter_ = new ConsoleObjectWriter();
        }
示例#2
0
        /// <summary>
        /// Initializes or resets scripting to default.
        /// </summary>
        private void Initialize()
        {
            var scriptOptions = ScriptOptions.Default.WithImports(ScriptCompiler.DefaultUsings).AddReferences(ScriptCompiler.DefaultAssemblyReferences);

            var originalSourceResolver   = scriptOptions.SourceResolver;
            var originalMetadataResolver = scriptOptions.MetadataResolver;

            metadataResolver = new ScriptExecution.MetadataResolver(originalMetadataResolver);
            sourceResolver   = new ScriptExecution.SourceResolver(originalSourceResolver);
            scriptOptions    = scriptOptions.WithMetadataResolver(metadataResolver);
            scriptOptions    = scriptOptions.WithSourceResolver(sourceResolver);

            importedCode = string.Empty;
            scriptBase   = Behavior.GetInteractiveScriptBase();
            scriptState  = CSharpScript.RunAsync(string.Join("\n", ScriptCompiler.DefaultAliases.Select(s => $"using {s};")), scriptOptions, scriptBase).Result;

            Context.SetUserTypeMetadata(Behavior.GetResetUserTypeMetadata());
        }