未验证 提交 78d2ed42 编写于 作者: F filipw

added a new Create Script overload

上级 2710583c
......@@ -53,6 +53,19 @@ public static Script<object> Create(string code, ScriptOptions options = null, T
return Create<object>(code, options, globalsType, assemblyLoader);
}
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
/// <summary>
/// Create a new C# script.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> representing the source code of the script.</param>
/// <param name="options">The script options.</param>
/// <param name="globalsType">Type of global object.</param>
/// <param name="assemblyLoader">Custom assembly loader.</param>
public static Script<object> Create(Stream stream, ScriptOptions options = null, Type globalsType = null, InteractiveAssemblyLoader assemblyLoader = null)
{
return Create<object>(stream, options, globalsType, assemblyLoader);
}
/// <summary>
/// Run a C# script.
/// </summary>
......
static Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.Create(System.IO.Stream stream, Microsoft.CodeAnalysis.Scripting.ScriptOptions options = null, System.Type globalsType = null, Microsoft.CodeAnalysis.Scripting.Hosting.InteractiveAssemblyLoader assemblyLoader = null) -> Microsoft.CodeAnalysis.Scripting.Script<object>
static Microsoft.CodeAnalysis.CSharp.Scripting.CSharpScript.Create<T>(System.IO.Stream stream, Microsoft.CodeAnalysis.Scripting.ScriptOptions options = null, System.Type globalsType = null, Microsoft.CodeAnalysis.Scripting.Hosting.InteractiveAssemblyLoader assemblyLoader = null) -> Microsoft.CodeAnalysis.Scripting.Script<T>
\ No newline at end of file
......@@ -30,6 +30,13 @@ public void TestCreateScript()
Assert.Equal("1 + 2", script.Code);
}
[Fact]
public void TestCreateFromStreamScript()
{
var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")));
Assert.Equal("1 + 2", script.Code);
}
[Fact]
public async Task TestGetCompilation()
{
......@@ -39,7 +46,7 @@ public async Task TestGetCompilation()
}
[Fact]
public async Task TestGetCompilation_SourceText()
public async Task TestGetCompilationSourceText()
{
var state = await CSharpScript.RunAsync("1 + 2", globals: new ScriptTests());
var compilation = state.Script.GetCompilation();
......@@ -85,6 +92,15 @@ public async Task TestCreateAndRunScript()
Assert.Equal(3, state.ReturnValue);
}
[Fact]
public async Task TestCreateFromStreamAndRunScript()
{
var script = CSharpScript.Create(new MemoryStream(Encoding.UTF8.GetBytes("1 + 2")));
var state = await script.RunAsync();
Assert.Same(script, state.Script);
Assert.Equal(3, state.ReturnValue);
}
[Fact]
public async Task TestEvalScript()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册