Пример #1
0
        private static void AnalyzeModelDesignerSpec(SymbolAnalysisContext context, ISymbol symbol, ITypeSymbol type, AttributeData attribute)
        {
            var spec = attribute.GetModelDesignerSpec(context.Compilation);

            if (!spec.HasValue)
            {
                return;
            }

            var validOnTypes = spec.Value.ValidOnTypes;

            if (validOnTypes == null)
            {
                return;
            }

            validOnTypes = validOnTypes.Where(x => x != null).ToArray();
            if (!IsValid(type, validOnTypes))
            {
                context.ReportDiagnostic(Diagnostic.Create(Rules.ModelDesignerSpecInvalidType, attribute.GetLocation(), attribute.AttributeClass, FormatString(validOnTypes), type));
                return;
            }

            if (ArgumentMissing(attribute, spec.Value.RequiresArgument))
            {
                context.ReportDiagnostic(Diagnostic.Create(Rules.ModelDesignerSpecRequiresArgument, attribute.GetLocation(), attribute.AttributeClass));
                return;
            }
        }