private static void CodeGenMvc(GeneratorExecutionContext context)
        {
            var syntaxReceiver = (MySyntaxReceiver)context.SyntaxReceiver;

            var sw = Stopwatch.StartNew();

            Log(context.Compilation, "MVC");
            try
            {
                var areas = MvcDiscoverer.DiscoverAreaControllerActions(context.Compilation, syntaxReceiver.PossibleControllers).ToList();

                using var sourceWriter = new StringWriter();
                using var writer       = new IndentedTextWriter(sourceWriter, "    ");

                CodeGenerator.WriteUrlActions(writer, areas);

                context.AddSource("UrlActionGenerator_UrlHelperExtensions.Mvc.g.cs", SourceText.From(sourceWriter.ToString(), Encoding.UTF8));
            }
            catch (Exception ex)
            {
                context.ReportDiagnostic(Diagnostic.Create(Diagnostics.MvcCodeGenException, Location.None, ex.Message, ex.StackTrace));
                Log(context.Compilation, $"Exception during generating MVC: {ex.Message}\n{ex.StackTrace}");
            }

            sw.Stop();
            Log(context.Compilation, $"MVC step took: {sw.Elapsed.TotalMilliseconds}ms");
        }
Exemplo n.º 2
0
        public void Execute(GeneratorExecutionContext context)
        {
            var areas = MvcDiscoverer.DiscoverAreaControllerActions(context.Compilation).ToList();

            using var sourceWriter = new StringWriter();
            using var writer       = new IndentedTextWriter(sourceWriter, "    ");

            CodeGenerator.WriteUrlActions(writer, areas);

            context.AddSource("UrlSourceGenerator.g.cs", SourceText.From(sourceWriter.ToString(), Encoding.UTF8));
        }