private void AnalyzeCompilation(CompilationEndAnalysisContext context) { if (AssemblyHasPublicTypes(context.Compilation.Assembly)) { var comVisibleAttributeSymbol = WellKnownTypes.ComVisibleAttribute(context.Compilation); if (comVisibleAttributeSymbol == null) { return; } var attributeInstance = context.Compilation.Assembly.GetAttributes().FirstOrDefault(a => a.AttributeClass.Equals(comVisibleAttributeSymbol)); if (attributeInstance != null) { if (attributeInstance.ConstructorArguments.Length > 0 && attributeInstance.ConstructorArguments[0].Kind == TypedConstantKind.Primitive && attributeInstance.ConstructorArguments[0].Value != null & attributeInstance.ConstructorArguments[0].Value.Equals(true)) { // Has the attribute, with the value 'true'. context.ReportDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(FxCopRulesResources.CA1017_AttributeTrue, context.Compilation.Assembly.Name))); } } else { // No ComVisible attribute at all. context.ReportDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(FxCopRulesResources.CA1017_NoAttribute, context.Compilation.Assembly.Name))); } } return; }
private void AnalyzeCompilation(CompilationEndAnalysisContext context) { if (AssemblyHasPublicTypes(context.Compilation.Assembly)) { var comVisibleAttributeSymbol = WellKnownTypes.ComVisibleAttribute(context.Compilation); if (comVisibleAttributeSymbol == null) { return; } var attributeInstance = context.Compilation.Assembly.GetAttributes().FirstOrDefault(a => a.AttributeClass.Equals(comVisibleAttributeSymbol)); if (attributeInstance != null) { if (attributeInstance.ConstructorArguments.Length > 0 && attributeInstance.ConstructorArguments[0].Kind == TypedConstantKind.Primitive && attributeInstance.ConstructorArguments[0].Value != null & attributeInstance.ConstructorArguments[0].Value.Equals(true)) { // Has the attribute, with the value 'true'. context.ReportDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(FxCopRulesResources.CA1017_AttributeTrue, context.Compilation.Assembly.Name))); } } else { // No ComVisible attribute at all. context.ReportDiagnostic(Diagnostic.Create(Rule, Location.None, string.Format(FxCopRulesResources.CA1017_NoAttribute, context.Compilation.Assembly.Name))); } } return; }
private void AnalyzeCompilation(CompilationEndAnalysisContext context) { var assemblyVersionAttributeSymbol = WellKnownTypes.AssemblyVersionAttribute(context.Compilation); var assemblyComplianceAttributeSymbol = WellKnownTypes.CLSCompliantAttribute(context.Compilation); if (assemblyVersionAttributeSymbol == null && assemblyComplianceAttributeSymbol == null) { return; } bool assemblyVersionAttributeFound = false; bool assemblyComplianceAttributeFound = false; // Check all assembly level attributes for the target attribute foreach (var attribute in context.Compilation.Assembly.GetAttributes()) { if (attribute.AttributeClass.Equals(assemblyVersionAttributeSymbol)) { // Mark the version attribute as found assemblyVersionAttributeFound = true; } else if (attribute.AttributeClass.Equals(assemblyComplianceAttributeSymbol)) { // Mark the compliance attribute as found assemblyComplianceAttributeFound = true; } } // Check for the case where we do not have the target attribute defined at all in our metadata references. If so, how can they reference it if (assemblyVersionAttributeSymbol == null) { assemblyVersionAttributeFound = false; } if (assemblyComplianceAttributeSymbol == null) { assemblyComplianceAttributeFound = false; } // If there's at least one diagnostic to report, let's report them if (!assemblyComplianceAttributeFound || !assemblyVersionAttributeFound) { if (!assemblyVersionAttributeFound) { context.ReportDiagnostic(Diagnostic.Create(CA1016Rule, Location.None)); } if (!assemblyComplianceAttributeFound) { context.ReportDiagnostic(Diagnostic.Create(CA1014Rule, Location.None)); } } }
public void AnalyzeCompilation(CompilationEndAnalysisContext context) { foreach (var item in this.fieldDisposedMap) { if (!item.Value) { context.ReportDiagnostic(item.Key.CreateDiagnostic(Rule)); } } }
public void AnalyzeCompilation(CompilationEndAnalysisContext context) { foreach (var item in _fieldDisposedMap) { if (!item.Value) { context.ReportDiagnostic(item.Key.CreateDiagnostic(Rule)); } } }
public void OnCompilationEnd(CompilationEndAnalysisContext context) { foreach (var kv in _used.Where(kv => !kv.Value && (kv.Key.Locations.FirstOrDefault()?.IsInSource == true))) { context.CancellationToken.ThrowIfCancellationRequested(); var symbol = kv.Key; // report visible error only if symbol is not local symbol if (!(symbol is ILocalSymbol)) { context.ReportDiagnostic(Diagnostic.Create(s_rule, symbol.Locations[0], symbol.Locations.Skip(1), symbol.Name)); } // where code fix works foreach (var reference in symbol.DeclaringSyntaxReferences) { context.CancellationToken.ThrowIfCancellationRequested(); context.ReportDiagnostic(Diagnostic.Create(s_triggerRule, Location.Create(reference.SyntaxTree, reference.Span))); } } }
internal void AnalyzeCompilationEnd(CompilationEndAnalysisContext context) { foreach (var sourceSymbol in _sourceSymbolsToCheck) { var found = false; foreach (var type in sourceSymbol.GetBaseTypesAndThis()) { if (_typesWithSymbolDeclaredEventInvoked.Contains(type)) { found = true; break; } } if (!found) { var diagnostic = Diagnostic.Create(SymbolDeclaredEventRule, sourceSymbol.Locations[0], sourceSymbol.Name, _compilationType.Name, SymbolDeclaredEventName); context.ReportDiagnostic(diagnostic); } } }
private void AnalyzeCompilation(CompilationEndAnalysisContext context) { var assemblyVersionAttributeSymbol = WellKnownTypes.AssemblyVersionAttribute(context.Compilation); var assemblyComplianceAttributeSymbol = WellKnownTypes.CLSCompliantAttribute(context.Compilation); if (assemblyVersionAttributeSymbol == null && assemblyComplianceAttributeSymbol == null) { return; } bool assemblyVersionAttributeFound = false; bool assemblyComplianceAttributeFound = false; // Check all assembly level attributes for the target attribute foreach (var attribute in context.Compilation.Assembly.GetAttributes()) { if (attribute.AttributeClass.Equals(assemblyVersionAttributeSymbol)) { // Mark the version attribute as found assemblyVersionAttributeFound = true; } else if (attribute.AttributeClass.Equals(assemblyComplianceAttributeSymbol)) { // Mark the compliance attribute as found assemblyComplianceAttributeFound = true; } } // Check for the case where we do not have the target attribute defined at all in our metadata references. If so, how can they reference it if (assemblyVersionAttributeSymbol == null) { assemblyVersionAttributeFound = false; } if (assemblyComplianceAttributeSymbol == null) { assemblyComplianceAttributeFound = false; } // If there's at least one diagnostic to report, let's report them if (!assemblyComplianceAttributeFound || !assemblyVersionAttributeFound) { if (!assemblyVersionAttributeFound) { context.ReportDiagnostic(Diagnostic.Create(CA1016Rule, Location.None)); } if (!assemblyComplianceAttributeFound) { context.ReportDiagnostic(Diagnostic.Create(CA1014Rule, Location.None)); } } }