public void addDocument(string id, string contents, ICompilerInjector <SyntaxToken, SyntaxNode, SemanticModel> injector) { if (_documents .Where(doc => doc.Id == id) .Any()) { throw new InvalidOperationException(); } var ext = Path.GetExtension(id); var compiler = null as RoslynCompiler; var tool = null as ICompilationTool; var hash = 0; if (string.IsNullOrEmpty(ext)) { compiler = new RoslynCompiler(_environment, _scope); injector.apply(compiler); } else if (ext == ".cs") { addCSharpFile(id, contents); } else { if (_tools.TryGetValue(ext, out tool)) { var storage = _environment.storage(); hash = storage == null ? hash : storage.cachedId(id); } } var newDoc = new CompilationDocument { Id = id, Stage = CompilerStage.Started, Compiler = compiler, Tool = tool, Hash = hash }; if (compiler != null) { newDoc.Stage = CompilerStage.Started; newDoc.Document = new RoslynDocument(compiler.Scope, contents, id); var documentInjector = newDoc.Compiler as IDocumentInjector <SyntaxToken, SyntaxNode, SemanticModel>; documentInjector.apply(newDoc.Document); } else { newDoc.Contents = contents; } _documents.Add(newDoc); }
public void addDocument(string id, string contents, ICompilerInjector<SyntaxToken, SyntaxNode, SemanticModel> injector) { if (_documents .Where(doc => doc.Id == id) .Any()) throw new InvalidOperationException(); var ext = Path.GetExtension(id); var compiler = null as RoslynCompiler; var tool = null as ICompilationTool; var hash = 0; if (string.IsNullOrEmpty(ext)) { compiler = new RoslynCompiler(_environment, _scope); injector.apply(compiler); } else if (ext == ".cs") { addCSharpFile(id, contents); } else { if (_tools.TryGetValue(ext, out tool)) { var storage = _environment.storage(); hash = storage == null ? hash : storage.cachedId(id); } } var newDoc = new CompilationDocument { Id = id, Stage = CompilerStage.Started, Compiler = compiler, Tool = tool, Hash = hash }; if (compiler != null) { newDoc.Stage = CompilerStage.Started; newDoc.Document = new RoslynDocument(compiler.Scope, contents, id); var documentInjector = newDoc.Compiler as IDocumentInjector<SyntaxToken, SyntaxNode, SemanticModel>; documentInjector.apply(newDoc.Document); } else newDoc.Contents = contents; _documents.Add(newDoc); }