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

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

            if (!CommandOptionSymbol.IsOptionProperty(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 option = CommandOptionSymbol.TryResolve(property);

        if (option is null)
        {
            return;
        }

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

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

        if (!converterImplementsInterface)
        {
            context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
        }
    }
    private void Analyze(
        SyntaxNodeAnalysisContext context,
        PropertyDeclarationSyntax propertyDeclaration,
        IPropertySymbol property)
    {
        var option = CommandOptionSymbol.TryResolve(property);

        if (option is null)
        {
            return;
        }

        foreach (var validatorType in option.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;
            }
        }
    }
Exemplo n.º 4
0
    private void Analyze(
        SyntaxNodeAnalysisContext context,
        PropertyDeclarationSyntax propertyDeclaration,
        IPropertySymbol property)
    {
        if (property.ContainingType is null)
        {
            return;
        }

        var option = CommandOptionSymbol.TryResolve(property);

        if (option is null)
        {
            return;
        }

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

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

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

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

            if (string.Equals(option.Name, otherOption.Name, StringComparison.OrdinalIgnoreCase))
            {
                context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
            }
        }
    }
Exemplo n.º 5
0
    private void Analyze(
        SyntaxNodeAnalysisContext context,
        PropertyDeclarationSyntax propertyDeclaration,
        IPropertySymbol property)
    {
        var option = CommandOptionSymbol.TryResolve(property);

        if (option is null)
        {
            return;
        }

        if (string.IsNullOrWhiteSpace(option.Name) && option.ShortName is null)
        {
            context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
        }
    }
Exemplo n.º 6
0
        private void Analyze(
            SyntaxNodeAnalysisContext context,
            PropertyDeclarationSyntax propertyDeclaration,
            IPropertySymbol property)
        {
            var option = CommandOptionSymbol.TryResolve(property);

            if (option is null)
            {
                return;
            }

            if (option.ShortName is null)
            {
                return;
            }

            if (!char.IsLetter(option.ShortName.Value))
            {
                context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
            }
        }
        private void Analyze(
            SyntaxNodeAnalysisContext context,
            PropertyDeclarationSyntax propertyDeclaration,
            IPropertySymbol property)
        {
            if (property.ContainingType is null)
                return;

            var option = CommandOptionSymbol.TryResolve(property);
            if (option is null)
                return;

            if (option.ShortName is null)
                return;

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

            foreach (var otherProperty in otherProperties)
            {
                var otherOption = CommandOptionSymbol.TryResolve(otherProperty);
                if (otherOption is null)
                    continue;

                if (otherOption.ShortName is null)
                    continue;

                if (option.ShortName == otherOption.ShortName)
                {
                    context.ReportDiagnostic(CreateDiagnostic(propertyDeclaration.GetLocation()));
                }
            }
        }