public static string?GetSource(this Diagnostic diagnostic, IOpenApiElementRegistry elementRegistry) { if (diagnostic == null) { throw new ArgumentNullException(nameof(diagnostic)); } if (elementRegistry == null) { throw new ArgumentNullException(nameof(elementRegistry)); } SyntaxTree?syntaxTree = diagnostic.Location.SourceTree; if (syntaxTree == null) { return(null); } CompilationUnitSyntax compilationUnit = syntaxTree.GetCompilationUnitRoot(); return(compilationUnit.GetResourceNameAnnotation() ?? compilationUnit.GetElementAnnotations(elementRegistry).FirstOrDefault()?.ToString()); }