Exemplo n.º 1
0
        public static IEnumerable <PageAreaDescriptor> DiscoverAreaPages(Compilation compilation, IEnumerable <AdditionalText> additionalFiles, AnalyzerConfigOptions configOptions)
        {
            var pages = DiscoverRazorPages(additionalFiles, compilation, configOptions);

            foreach (var page in pages)
            {
                SourceGenerator.Log(compilation, "area:" + page.Area + ", page:" + page.Page + ", route:" + page.Route + ", model:" + page.Model);
            }

            var usingsByDirectory = GatherImplicitUsings(pages);

            foreach (var group in pages.GroupBy(page => page.Area))
            {
                var area = new PageAreaDescriptor(group.Key);

                foreach (var page in group)
                {
                    var model = GetPageModel(page, compilation, usingsByDirectory);

                    var modelParameters     = RouteDiscoverer.DiscoverModelParameters(model, compilation).ToList();
                    var modelParameterNames = modelParameters.Select(param => param.Name).ToList();

                    var routeParameters = RouteDiscoverer.DiscoverRouteParameters(page.Route).ToList();
                    routeParameters = routeParameters.ExceptBy(modelParameterNames, param => param.Name, StringComparer.OrdinalIgnoreCase).ToList();

                    foreach (var(pageHandler, method) in DiscoverMethods(model))
                    {
                        var methodParameters     = RouteDiscoverer.DiscoverMethodParameters(method).ToList();
                        var methodParameterNames = methodParameters.Select(param => param.Name).ToList();

                        var folder = area.GetFolder(page.Folder);
                        folder.Pages.Add(new PageDescriptor(
                                             area,
                                             page.Page,
                                             pageHandler,
                                             routeParameters.ExceptBy(methodParameterNames, param => param.Name, StringComparer.OrdinalIgnoreCase)
                                             .Concat(methodParameters)
                                             .Concat(modelParameters.ExceptBy(methodParameterNames, param => param.Name, StringComparer.OrdinalIgnoreCase))
                                             .ToList()));
                    }
                }

                SourceGenerator.Log(compilation, "Found: '" + area.Name + "', " + area.Pages.Count + " pages and " + area.Folders.Count + " folders");
                yield return(area);
            }
        }
Exemplo n.º 2
0
        public static ControllerDescriptor DiscoverControllerActions(INamedTypeSymbol controllerSymbol, AreaDescriptor area, IMethodSymbol disposableDispose)
        {
            var controllerName = RouteDiscoverer.DiscoverControllerName(controllerSymbol);
            var controller     = new ControllerDescriptor(area, controllerName);

            foreach (var actionSymbol in DiscoverActions(controllerSymbol, disposableDispose))
            {
                var actionName = RouteDiscoverer.DiscoverActionName(actionSymbol);
                var action     = new ActionDescriptor(controller, actionName);

                foreach (var parameter in RouteDiscoverer.DiscoverMethodParameters(actionSymbol))
                {
                    action.Parameters.Add(parameter);
                }

                controller.Actions.Add(action);
            }

            return(controller);
        }