diff --git a/src/Scripting/CSharp/CSharpScript.cs b/src/Scripting/CSharp/CSharpScript.cs index 1b97f0ce41b043a510301f626af7faee861d5494..581e98394f37504c01e27089a1225df13a04dbd5 100644 --- a/src/Scripting/CSharp/CSharpScript.cs +++ b/src/Scripting/CSharp/CSharpScript.cs @@ -24,8 +24,10 @@ public static class CSharpScript /// Type of global object. /// Custom assembly loader. /// The return type of the script + /// Code is null. public static Script Create(string code, ScriptOptions options = null, Type globalsType = null, InteractiveAssemblyLoader assemblyLoader = null) { + if (code == null) throw new ArgumentNullException(nameof(code)); return Script.CreateInitialScript(CSharpScriptCompiler.Instance, SourceText.From(code, options?.FileEncoding), options, globalsType, assemblyLoader); } @@ -52,8 +54,10 @@ public static Script Create(Stream code, ScriptOptions options = null, Typ /// The script options. /// Type of global object. /// Custom assembly loader. + /// Code is null. public static Script Create(string code, ScriptOptions options = null, Type globalsType = null, InteractiveAssemblyLoader assemblyLoader = null) { + if (code == null) throw new ArgumentNullException(nameof(code)); return Create(code, options, globalsType, assemblyLoader); } diff --git a/src/Scripting/CSharpTest/ScriptTests.cs b/src/Scripting/CSharpTest/ScriptTests.cs index 4c7fd19ab2d9e49fe10a515a66ee27bbc31f3e8f..479948b6d07e05c4de96b3ba2bfa0bfc1a0e1d4e 100644 --- a/src/Scripting/CSharpTest/ScriptTests.cs +++ b/src/Scripting/CSharpTest/ScriptTests.cs @@ -31,6 +31,12 @@ public void TestCreateScript() Assert.Equal("1 + 2", script.Code); } + [Fact] + public void TestCreateScript_CodeIsNull() + { + Assert.Throws(() => 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(() => CSharpScript.Create((Stream)null)); + } + [Fact] public async Task TestGetCompilation() {