private void Analyze(
            SyntaxNodeAnalysisContext context,
            PropertyDeclarationSyntax propertyDeclaration,
            IPropertySymbol property)
        {
            if (property.ContainingType is null)
            {
                return;
            }

            if (property.ContainingType.IsAbstract)
            {
                return;
            }

            if (!CommandParameterSymbol.IsParameterProperty(property))
            {
                return;
            }

            var isInsideCommand = property
                                  .ContainingType
                                  .AllInterfaces
                                  .Any(s => s.DisplayNameMatches(SymbolNames.CliFxCommandInterface));

            if (!isInsideCommand)
            {
                context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
            }
        }
        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;
                }
            }
        }
Beispiel #3
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()));
        }
    }
Beispiel #4
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()));
            }
        }
    }
        private void Analyze(
            SyntaxNodeAnalysisContext context,
            PropertyDeclarationSyntax propertyDeclaration,
            IPropertySymbol property)
        {
            if (property.ContainingType is null)
            {
                return;
            }

            if (!CommandParameterSymbol.IsParameterProperty(property))
            {
                return;
            }

            if (IsScalar(property.Type))
            {
                return;
            }

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

            foreach (var otherProperty in otherProperties)
            {
                if (!CommandParameterSymbol.IsParameterProperty(otherProperty))
                {
                    continue;
                }

                if (!IsScalar(otherProperty.Type))
                {
                    context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
                }
            }
        }