// Needed to support configuration of diagnostics and code fixes/refactorings. public void ProcessAssembly(Assembly asm) { try { foreach (var type in asm.GetTypes()) { //HACK: Workaround for missing UI if (type == typeof(Microsoft.CodeAnalysis.GenerateOverrides.GenerateOverridesCodeRefactoringProvider)) { continue; } if (type == typeof(Microsoft.CodeAnalysis.AddMissingReference.AbstractAddMissingReferenceCodeFixProvider)) { continue; } var analyzerAttr = (DiagnosticAnalyzerAttribute)type.GetCustomAttributes(typeof(DiagnosticAnalyzerAttribute), false).FirstOrDefault(); if (analyzerAttr != null) { try { var analyzer = (DiagnosticAnalyzer)Activator.CreateInstance(type); var descriptor = new CodeDiagnosticDescriptor(analyzerAttr.Languages, type); foreach (var diag in analyzer.SupportedDiagnostics) { if (!IsDiagnosticSupported(diag)) { continue; } diagnosticTable[diag.Id] = descriptor; } diagnostics.Add(descriptor); } catch (Exception e) { LoggingService.LogError($"error while adding diagnostic analyzer {type} from assembly {asm.FullName}", e); } } var exportAttr = type.GetCustomAttributes(typeof(ExportCodeRefactoringProviderAttribute), false).FirstOrDefault() as ExportCodeRefactoringProviderAttribute; if (exportAttr != null) { refactoringTable[type] = new CodeRefactoringDescriptor(type, exportAttr); } } } catch (ReflectionTypeLoadException ex) { foreach (var subException in ex.LoaderExceptions) { LoggingService.LogError("Error while loading diagnostics in " + asm.FullName, subException); } throw; } }
public bool TryGetRefactoringDescriptor(Type t, out CodeRefactoringDescriptor desc) { return(refactoringTable.TryGetValue(t, out desc)); }