forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpScriptEngine.cs
More file actions
37 lines (31 loc) · 1.12 KB
/
CSharpScriptEngine.cs
File metadata and controls
37 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.CodeAnalysis.Scripting.CSharp;
using ScriptCs.Contracts;
using ScriptCs.Engine.Common;
namespace ScriptCs.CSharp
{
public class CSharpScriptEngine : CommonScriptEngine
{
public CSharpScriptEngine(IScriptHostFactory scriptHostFactory, ILogProvider logProvider) : base(scriptHostFactory, logProvider)
{
}
protected override ScriptState GetScriptState(string code, object globals)
{
return CSharpScript.Run(code, ScriptOptions, globals);
}
protected bool IsCompleteSubmission(string code)
{
//invalid REPL command
if (code.StartsWith(":"))
{
return true;
}
var options = new CSharpParseOptions(LanguageVersion.CSharp6, DocumentationMode.Parse,
SourceCodeKind.Interactive, null);
var syntaxTree = SyntaxFactory.ParseSyntaxTree(code, options: options);
return SyntaxFactory.IsCompleteSubmission(syntaxTree);
}
}
}