Exemplo n.º 1
0
        private void AnalyzeSymbol(SymbolUsageAnalysisContext context, PlatformCompatOptions options)
        {
            var symbol = context.Symbol;

            // We only want to handle a specific set of symbols
            var isApplicable = symbol.Kind == SymbolKind.Event ||
                               symbol.Kind == SymbolKind.Field ||
                               symbol.Kind == SymbolKind.Method ||
                               symbol.Kind == SymbolKind.NamedType ||
                               symbol.Kind == SymbolKind.Namespace ||
                               symbol.Kind == SymbolKind.Property;

            if (!isApplicable)
            {
                return;
            }

            if (!_store.Value.TryLookup(symbol, out var entry))
            {
                return;
            }

            var api        = symbol.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat);
            var location   = context.GetLocation();
            var diagnostic = Diagnostic.Create(Rule, location, api);

            context.ReportDiagnostic(diagnostic);
        }
        private void AnalyzeSymbol(SymbolUsageAnalysisContext context, PlatformCompatOptions options)
        {
            var symbol = context.Symbol;

            // We only want to handle a specific set of symbols
            var isApplicable = symbol.Kind == SymbolKind.Method ||
                               symbol.Kind == SymbolKind.Property ||
                               symbol.Kind == SymbolKind.Event;

            if (!isApplicable)
            {
                return;
            }

            if (!_store.Value.TryLookup(symbol, out var entry))
            {
                return;
            }

            // Check that the affected platforms aren't suppressed
            var maskedPlatforms = entry.Data & ~options.IgnoredPlatforms;

            if (maskedPlatforms == Platform.None)
            {
                return;
            }

            var api        = symbol.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat);
            var location   = context.GetLocation();
            var list       = maskedPlatforms.ToFriendlyString();
            var diagnostic = Diagnostic.Create(Rule, location, api, list);

            context.ReportDiagnostic(diagnostic);
        }
Exemplo n.º 3
0
        private void AnalyzeSymbol(SymbolUsageAnalysisContext context)
        {
            var symbol = context.Symbol;

            // We only want to handle a specific set of symbols
            var isApplicable = symbol.Kind == SymbolKind.Event ||
                               symbol.Kind == SymbolKind.Field ||
                               symbol.Kind == SymbolKind.Method ||
                               symbol.Kind == SymbolKind.NamedType ||
                               symbol.Kind == SymbolKind.Namespace ||
                               symbol.Kind == SymbolKind.Property;

            if (!isApplicable)
            {
                return;
            }

            if (!_store.TryLookup(symbol, out var entry))
            {
                return;
            }

            if (symbol.Locations.Any(l => l.IsInSource))
            {
                return;
            }

            var api      = symbol.ToDisplayString(SymbolDisplayFormat.CSharpShortErrorMessageFormat);
            var location = context.GetLocation();

            foreach (var diagnosticId in entry.Data)
            {
                var descriptor = DescriptorById[diagnosticId];
                var diagnostic = Diagnostic.Create(descriptor, location, api);
                context.ReportDiagnostic(diagnostic);
            }
        }