public void add(string file, int fileId, string contents) { if (_files.ContainsKey(file)) { throw new InvalidOperationException("duplicate file"); } _compilation.addDocument(file, contents, getInjector(file)); _files[file] = fileId; _dirty = true; }
public static dynamic ExecuteTest(string text, Action <ICompiler <SyntaxToken, SyntaxNode, SemanticModel> > config) { var compilation = new Excess.Compiler.Roslyn.Compilation(null); var injector = new CompositeInjector <SyntaxToken, SyntaxNode, SemanticModel>(new[] { _main, new DelegateInjector <SyntaxToken, SyntaxNode, SemanticModel>(compiler => config(compiler)) }); compilation.addDocument("test", text, injector); Assembly assembly = compilation.build(); if (assembly == null) { //debug StringBuilder errorLines = new StringBuilder(); foreach (var error in compilation.errors()) { errorLines.AppendLine(error.ToString()); } var errorString = errorLines.ToString(); return(null); } Type testtype = assembly.GetType("testclass"); //var method = console.GetMethod("test", BindingFlags.Static); var result = new Dictionary <string, object>(); testtype.InvokeMember("test", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[] { result }); var xo = new ExpandoObject(); var xod = xo as IDictionary <string, object>; foreach (var kp in result) { xod.Add(kp.Key, kp.Value); } return(xo); }
public static dynamic ExecuteTest(string text, Action<ICompiler<SyntaxToken, SyntaxNode, SemanticModel>> config) { var compilation = new Excess.Compiler.Roslyn.Compilation(null); var injector = new CompositeInjector<SyntaxToken, SyntaxNode, SemanticModel>(new[] { _main, new DelegateInjector<SyntaxToken, SyntaxNode, SemanticModel>(compiler => config(compiler)) }); compilation.addDocument("test", text, injector); Assembly assembly = compilation.build(); if (assembly == null) { //debug StringBuilder errorLines = new StringBuilder(); foreach (var error in compilation.errors()) { errorLines.AppendLine(error.ToString()); } var errorString = errorLines.ToString(); return null; } Type testtype = assembly.GetType("testclass"); //var method = console.GetMethod("test", BindingFlags.Static); var result = new Dictionary<string, object>(); testtype.InvokeMember("test", BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic, null, null, new object[] { result }); var xo = new ExpandoObject(); var xod = xo as IDictionary<string, object>; foreach (var kp in result) xod.Add(kp.Key, kp.Value); return xo; }