private static void AnalyzeModelDeclarationAttribute(SymbolAnalysisContext context, INamedTypeSymbol modelType, AttributeData attribute) { var compilation = context.Compilation; var spec = attribute.AttributeClass.GetModelDeclarationSpec(compilation); if (!spec.HasValue) { return; } var specValue = spec.Value; var name = attribute.GetStringArgument(); if (name == null) { return; } var implementation = GetImplementation(modelType, name, specValue); if (implementation == null) { var isProperty = specValue.IsProperty; var parameterTypes = specValue.ParameterTypes; var returnType = specValue.ReturnType; context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementation, attribute.GetLocation(), (isProperty ? Resources.StringFormatArg_Property : Resources.StringFormatArg_Method), name, returnType, parameterTypes.FormatString())); return; } var crossRefAttributeType = attribute.GetCrossReferenceAttributeType(compilation); if (crossRefAttributeType == null) { return; } if (!implementation.HasAttribute(crossRefAttributeType)) { context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementationAttribute, implementation.Locations[0], crossRefAttributeType)); } }
private static void AnalyzeDeclaration(SymbolAnalysisContext context, INamedTypeSymbol dbType, IPropertySymbol dbTable, AttributeData attribute, HashSet <string> names) { var name = attribute.GetStringArgument(); if (name == null) { return; } if (names.Contains(name)) { context.ReportDiagnostic(Diagnostic.Create(Rules.DuplicateDeclarationAttribute, attribute.GetLocation(), attribute.AttributeClass, name)); return; } names.Add(name); var modelType = dbTable.GetModelType(); if (modelType == null) { return; } var compilation = context.Compilation; var implementation = GetImplementation(dbType, name, modelType, compilation); if (implementation == null) { var keyMappingType = compilation.GetKnownType(KnownTypes.KeyMapping); context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementation, attribute.GetLocation(), Resources.StringFormatArg_Method, name, keyMappingType, modelType)); return; } var implementationAttribute = compilation.GetKnownType(KnownTypes._RelationshipAttribute); if (!implementation.HasAttribute(implementationAttribute)) { context.ReportDiagnostic(Diagnostic.Create(Rules.MissingImplementationAttribute, implementation.Locations[0], implementationAttribute)); } }