public string CacheLocation(string url) { if (_sourceFileMap == null) { return(url); } SourceFileDetails details = _sourceFileMap.Details(url); if (details == null) { return(url); } return(SourceFileMap.ComputeCachedPath(_pdbFilePath, details.SourceUrl)); }
public SyntaxTree ParseFile(string filePath, string pdbPath) { // Determine the local path to the file (if it's a URL) string localPath = filePath; if (filePath.StartsWith("http", StringComparison.OrdinalIgnoreCase)) { localPath = SourceFileMap.ComputeCachedPath(pdbPath, filePath); } if (!File.Exists(localPath)) { return(null); } // Much like Roslyn CSharpCompiler.CreateCompilation SourceText fileContent = null; using (var stream = new FileStream(localPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, bufferSize: 1, options: FileOptions.None)) { fileContent = SourceText.From(stream); } // Parse the file but keep the original path or URL as the path (so locations from Roslyn point to it) string extension = Path.GetExtension(filePath).ToLowerInvariant(); switch (extension) { case ".cs": return(CSharpSyntaxTree.ParseText(fileContent, path: filePath)); case ".vb": return(VisualBasicSyntaxTree.ParseText(fileContent, path: filePath)); default: return(null); } }