public IEnumerable<CompilerMessage> GetMessages(Predicate<CompilerMessage> messageFilter = null) { foreach (Diagnostic diagnostic in _result.Diagnostics) { // Translating error diagnostic SourceSpan property to source Line and Column https://social.msdn.microsoft.com/Forums/vstudio/en-US/cebf07d6-f817-4c24-93f2-c66f05a23e20/translating-error-diagnostic-sourcespan-property-to-source-line-and-column?forum=roslyn //var lineSpan = Location.SourceTree.GetLineSpan(Location.SourceSpan, usePreprocessorDirectives: false); string fileName = null; int? column = null; int? line = null; Location location = diagnostic.Location; if (location != null && location.SourceTree != null) { fileName = location.SourceTree.FilePath; var lineSpan = location.SourceTree.GetLineSpan(location.SourceSpan); column = lineSpan.StartLinePosition.Character + 1; line = lineSpan.StartLinePosition.Line + 1; } // CompilerMessage message = new CompilerMessage { Id = diagnostic.Id, Message = diagnostic.GetMessage(), Severity = GetSeverity(diagnostic.Severity), FileName = fileName, Column = column, Line = line }; if (messageFilter != null && !messageFilter(message)) continue; if (_messageFilter != null && !_messageFilter(message)) continue; yield return message; } }
public IEnumerable <CompilerMessage> GetMessages(Predicate <CompilerMessage> messageFilter = null) { foreach (Diagnostic diagnostic in _result.Diagnostics) { // Translating error diagnostic SourceSpan property to source Line and Column https://social.msdn.microsoft.com/Forums/vstudio/en-US/cebf07d6-f817-4c24-93f2-c66f05a23e20/translating-error-diagnostic-sourcespan-property-to-source-line-and-column?forum=roslyn //var lineSpan = Location.SourceTree.GetLineSpan(Location.SourceSpan, usePreprocessorDirectives: false); string fileName = null; int? column = null; int? line = null; Location location = diagnostic.Location; if (location != null && location.SourceTree != null) { fileName = location.SourceTree.FilePath; var lineSpan = location.SourceTree.GetLineSpan(location.SourceSpan); column = lineSpan.StartLinePosition.Character + 1; line = lineSpan.StartLinePosition.Line + 1; } // CompilerMessage message = new CompilerMessage { Id = diagnostic.Id, Message = diagnostic.GetMessage(), Severity = GetSeverity(diagnostic.Severity), FileName = fileName, Column = column, Line = line }; if (messageFilter != null && !messageFilter(message)) { continue; } if (_messageFilter != null && !_messageFilter(message)) { continue; } yield return(message); } }
public IEnumerable<CompilerMessage> GetMessages(Predicate<CompilerMessage> messageFilter = null) { foreach (CompilerError error in _result.Errors) { //yield return new CompilerMessage { Id = error.ErrorNumber, Message = error.ErrorText, IsWarning = error.IsWarning, FileName = error.FileName, Column = error.Column, Line = error.Line }; //messageFilter CompilerMessage message = new CompilerMessage { Id = error.ErrorNumber, Message = error.ErrorText, Severity = error.IsWarning ? CompilerMessageSeverity.Warning : CompilerMessageSeverity.Error, FileName = error.FileName, Column = error.Column, Line = error.Line }; if (messageFilter != null && !messageFilter(message)) continue; yield return message; } }
public IEnumerable <CompilerMessage> GetMessages(Predicate <CompilerMessage> messageFilter = null) { foreach (CompilerError error in _result.Errors) { //yield return new CompilerMessage { Id = error.ErrorNumber, Message = error.ErrorText, IsWarning = error.IsWarning, FileName = error.FileName, Column = error.Column, Line = error.Line }; //messageFilter CompilerMessage message = new CompilerMessage { Id = error.ErrorNumber, Message = error.ErrorText, Severity = error.IsWarning ? CompilerMessageSeverity.Warning : CompilerMessageSeverity.Error, FileName = error.FileName, Column = error.Column, Line = error.Line }; if (messageFilter != null && !messageFilter(message)) { continue; } yield return(message); } }