private List <EventHandlerData> GetEventHandlerData(TagHelperDescriptorProviderContext context, Compilation compilation, INamedTypeSymbol eventHandlerAttribute)
        {
            var types   = new List <INamedTypeSymbol>();
            var visitor = new EventHandlerDataVisitor(types);

            var targetAssembly = context.Items.GetTargetAssembly();

            if (targetAssembly is not null)
            {
                visitor.Visit(targetAssembly.GlobalNamespace);
            }
            else
            {
                visitor.Visit(compilation.Assembly.GlobalNamespace);
                foreach (var reference in compilation.References)
                {
                    if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly)
                    {
                        visitor.Visit(assembly.GlobalNamespace);
                    }
                }
            }

            var results = new List <EventHandlerData>();

            for (var i = 0; i < types.Count; i++)
            {
                var type       = types[i];
                var attributes = type.GetAttributes();

                // Not handling duplicates here for now since we're the primary ones extending this.
                // If we see users adding to the set of event handler constructs we will want to add deduplication
                // and potentially diagnostics.
                for (var j = 0; j < attributes.Length; j++)
                {
                    var attribute = attributes[j];

                    if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, eventHandlerAttribute))
                    {
                        var enablePreventDefault  = false;
                        var enableStopPropagation = false;
                        if (attribute.ConstructorArguments.Length == 4)
                        {
                            enablePreventDefault  = (bool)attribute.ConstructorArguments[2].Value;
                            enableStopPropagation = (bool)attribute.ConstructorArguments[3].Value;
                        }

                        results.Add(new EventHandlerData(
                                        type.ContainingAssembly.Name,
                                        type.ToDisplayString(),
                                        (string)attribute.ConstructorArguments[0].Value,
                                        (INamedTypeSymbol)attribute.ConstructorArguments[1].Value,
                                        enablePreventDefault,
                                        enableStopPropagation));
                    }
                }
            }

            return(results);
        }
        private List <EventHandlerData> GetEventHandlerData(Compilation compilation)
        {
            var eventHandlerAttribute = compilation.GetTypeByMetadataName(BlazorApi.EventHandlerAttribute.FullTypeName);

            if (eventHandlerAttribute == null)
            {
                // This won't likely happen, but just in case.
                return(new List <EventHandlerData>());
            }

            var types   = new List <INamedTypeSymbol>();
            var visitor = new EventHandlerDataVisitor(types);

            // Visit the primary output of this compilation, as well as all references.
            visitor.Visit(compilation.Assembly);
            foreach (var reference in compilation.References)
            {
                // We ignore .netmodules here - there really isn't a case where they are used by user code
                // even though the Roslyn APIs all support them.
                if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly)
                {
                    visitor.Visit(assembly);
                }
            }

            var results = new List <EventHandlerData>();

            for (var i = 0; i < types.Count; i++)
            {
                var type       = types[i];
                var attributes = type.GetAttributes();

                // Not handling duplicates here for now since we're the primary ones extending this.
                // If we see users adding to the set of event handler constructs we will want to add deduplication
                // and potentially diagnostics.
                for (var j = 0; j < attributes.Length; j++)
                {
                    var attribute = attributes[j];

                    if (attribute.AttributeClass == eventHandlerAttribute)
                    {
                        results.Add(new EventHandlerData(
                                        type.ContainingAssembly.Name,
                                        type.ToDisplayString(),
                                        (string)attribute.ConstructorArguments[0].Value,
                                        (INamedTypeSymbol)attribute.ConstructorArguments[1].Value));
                    }
                }
            }

            return(results);
        }
        private List <EventHandlerData> GetEventHandlerData(TagHelperDescriptorProviderContext context, Compilation compilation, INamedTypeSymbol eventHandlerAttribute)
        {
            var types   = new List <INamedTypeSymbol>();
            var visitor = new EventHandlerDataVisitor(types);

            var discoveryMode = context.Items.GetTagHelperDiscoveryFilter();

            if ((discoveryMode & TagHelperDiscoveryFilter.CurrentCompilation) == TagHelperDiscoveryFilter.CurrentCompilation)
            {
                visitor.Visit(compilation.Assembly);
            }

            if ((discoveryMode & TagHelperDiscoveryFilter.ReferenceAssemblies) == TagHelperDiscoveryFilter.ReferenceAssemblies)
            {
                foreach (var reference in compilation.References)
                {
                    // We ignore .netmodules here - there really isn't a case where they are used by user code
                    // even though the Roslyn APIs all support them.
                    if (compilation.GetAssemblyOrModuleSymbol(reference) is IAssemblySymbol assembly)
                    {
                        visitor.Visit(assembly);
                    }
                }
            }

            var results = new List <EventHandlerData>();

            for (var i = 0; i < types.Count; i++)
            {
                var type       = types[i];
                var attributes = type.GetAttributes();

                // Not handling duplicates here for now since we're the primary ones extending this.
                // If we see users adding to the set of event handler constructs we will want to add deduplication
                // and potentially diagnostics.
                for (var j = 0; j < attributes.Length; j++)
                {
                    var attribute = attributes[j];

                    if (SymbolEqualityComparer.Default.Equals(attribute.AttributeClass, eventHandlerAttribute))
                    {
                        var enablePreventDefault  = false;
                        var enableStopPropagation = false;
                        if (attribute.ConstructorArguments.Length == 4)
                        {
                            enablePreventDefault  = (bool)attribute.ConstructorArguments[2].Value;
                            enableStopPropagation = (bool)attribute.ConstructorArguments[3].Value;
                        }

                        results.Add(new EventHandlerData(
                                        type.ContainingAssembly.Name,
                                        type.ToDisplayString(),
                                        (string)attribute.ConstructorArguments[0].Value,
                                        (INamedTypeSymbol)attribute.ConstructorArguments[1].Value,
                                        enablePreventDefault,
                                        enableStopPropagation));
                    }
                }
            }

            return(results);
        }