未验证 提交 3160a3e0 编写于 作者: F filipw

added missing null check in CSharpScript Create

上级 931fdf92
......@@ -24,8 +24,10 @@ public static class CSharpScript
/// <param name="globalsType">Type of global object.</param>
/// <param name="assemblyLoader">Custom assembly loader.</param>
/// <typeparam name="T">The return type of the script</typeparam>
/// <exception cref="ArgumentNullException">Code is null.</exception>
public static Script<T> Create<T>(string code, ScriptOptions options = null, Type globalsType = null, InteractiveAssemblyLoader assemblyLoader = null)
{
if (code == null) throw new ArgumentNullException(nameof(code));
return Script.CreateInitialScript<T>(CSharpScriptCompiler.Instance, SourceText.From(code, options?.FileEncoding), options, globalsType, assemblyLoader);
}
......@@ -52,8 +54,10 @@ public static Script<T> Create<T>(Stream code, ScriptOptions options = null, Typ
/// <param name="options">The script options.</param>
/// <param name="globalsType">Type of global object.</param>
/// <param name="assemblyLoader">Custom assembly loader.</param>
/// <exception cref="ArgumentNullException">Code is null.</exception>
public static Script<object> Create(string code, ScriptOptions options = null, Type globalsType = null, InteractiveAssemblyLoader assemblyLoader = null)
{
if (code == null) throw new ArgumentNullException(nameof(code));
return Create<object>(code, options, globalsType, assemblyLoader);
}
......
......@@ -31,6 +31,12 @@ public void TestCreateScript()
Assert.Equal("1 + 2", script.Code);
}
[Fact]
public void TestCreateScript_CodeIsNull()
{
Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((string)null));
}
[Fact]
public void TestCreateFromStreamScript()
{
......@@ -38,6 +44,12 @@ public void TestCreateFromStreamScript()
Assert.Equal("1 + 2", script.Code);
}
[Fact]
public void TestCreateFromStreamScript_StreamIsNull()
{
Assert.Throws<ArgumentNullException>(() => CSharpScript.Create((Stream)null));
}
[Fact]
public async Task TestGetCompilation()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册