private void Analyze(
            SyntaxNodeAnalysisContext context,
            PropertyDeclarationSyntax propertyDeclaration,
            IPropertySymbol property)
        {
            var parameter = CommandParameterSymbol.TryResolve(property);

            if (parameter is null)
            {
                return;
            }

            foreach (var validatorType in parameter.ValidatorTypes)
            {
                // We check against an internal interface because checking against a generic class is a pain
                var validatorImplementsInterface = validatorType
                                                   .AllInterfaces
                                                   .Any(s => s.DisplayNameMatches(SymbolNames.CliFxBindingValidatorInterface));

                if (!validatorImplementsInterface)
                {
                    context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));

                    // No need to report multiple identical diagnostics on the same node
                    break;
                }
            }
        }
Exemple #2
0
    private void Analyze(
        SyntaxNodeAnalysisContext context,
        PropertyDeclarationSyntax propertyDeclaration,
        IPropertySymbol property)
    {
        var parameter = CommandParameterSymbol.TryResolve(property);

        if (parameter is null)
        {
            return;
        }

        if (parameter.ConverterType is null)
        {
            return;
        }

        // We check against an internal interface because checking against a generic class is a pain
        var converterImplementsInterface = parameter
                                           .ConverterType
                                           .AllInterfaces
                                           .Any(s => s.DisplayNameMatches(SymbolNames.CliFxBindingConverterInterface));

        if (!converterImplementsInterface)
        {
            context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
        }
    }
Exemple #3
0
    private void Analyze(
        SyntaxNodeAnalysisContext context,
        PropertyDeclarationSyntax propertyDeclaration,
        IPropertySymbol property)
    {
        if (property.ContainingType is null)
        {
            return;
        }

        var parameter = CommandParameterSymbol.TryResolve(property);

        if (parameter is null)
        {
            return;
        }

        if (string.IsNullOrWhiteSpace(parameter.Name))
        {
            return;
        }

        var otherProperties = property
                              .ContainingType
                              .GetMembers()
                              .OfType <IPropertySymbol>()
                              .Where(m => !m.Equals(property, SymbolEqualityComparer.Default))
                              .ToArray();

        foreach (var otherProperty in otherProperties)
        {
            var otherParameter = CommandParameterSymbol.TryResolve(otherProperty);
            if (otherParameter is null)
            {
                continue;
            }

            if (string.IsNullOrWhiteSpace(otherParameter.Name))
            {
                continue;
            }

            if (string.Equals(parameter.Name, otherParameter.Name, StringComparison.OrdinalIgnoreCase))
            {
                context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
            }
        }
    }