private void ReadAndWriteFile(string filePath) { Console.WriteLine("Checking file " + filePath); if (File.Exists(filePath)) { string fileContents = null; try { fileContents = File.ReadAllText(filePath); } catch (IOException) { } CsLanguageService languageService = new CsLanguageService(preprocessorDefinitions); CsDocument doc = null; try { doc = languageService.CreateCodeModel(fileContents, Path.GetFileName(filePath), filePath); } catch (SyntaxException) { } catch (Exception ex) { Assert.Fail("Exception from CodeModel: " + ex.GetType() + ", " + ex.Message + ". FilePath=" + filePath); } if (doc != null) { using (StringWriter writer = new StringWriter()) { doc.Write(writer); this.CompareDocs(fileContents, writer.ToString(), filePath); } } } }