0
방법/기능을 이용한 추가 : 나는 OK 테스트 통과로슬린 스크립트는 점점 오류 스크립트가 버그가있는 경우 테스트하기 위해 나는 방법을 개발
을 간단한 코드를 실행 한 경우
public static object Test(string code, string references)
{
try
{
Compilation compilation = CSharpScript.Create(code,
options: ScriptOptions.Default
.AddReferences(references)
.AddImports("System.Collections.Specialized", "System.Linq", "System.Net"),
globalsType: typeof(ScriptObject)
).GetCompilation();
using (var ms = new MemoryStream())
{
EmitResult result = compilation.Emit(ms);
if (!result.Success)
{
var failures = result.Diagnostics.Where(diagnostic =>
diagnostic.IsWarningAsError ||
diagnostic.Severity == DiagnosticSeverity.Error).Select(s => s.GetMessage());
return (new { Success = false, ErrorMessage = failures });
}
}
}
catch (Exception e)
{
return (new { Success = false, ErrorMessage = e.Message });
}
return (new { Success = true });
}
을하지만 코드에 추가하는 경우 메서드/함수, 예외가 발생했습니다. 예는 :
int Add(int x, int y) {
return x+y;
};
Add(1, 4)
내가 오류가
; 세미콜론, 메서드 또는 접근 자 블록이 유효하지 않은 경우에만 할당, 호출, 증분, 감소 및 새 개체 표현을 문으로 사용할 수 있습니다.
오류는 "return x + y;"에 있습니다. 문장을 추가하면 "int c = x + y;" 그 줄에서 오류가 발생합니다.
작동이 예상 되나요? 아닙니다.