public static void Register(RazorProjectEngineBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            FunctionsDirective.Register(builder);
            ImplementsDirective.Register(builder);
            InheritsDirective.Register(builder);
            InjectDirective.Register(builder);
            LayoutDirective.Register(builder);
            PageDirective.Register(builder);

            builder.Features.Remove(builder.Features.OfType <IImportProjectFeature>().Single());
            builder.Features.Add(new BlazorImportProjectFeature());

            var index = builder.Phases.IndexOf(builder.Phases.OfType <IRazorCSharpLoweringPhase>().Single());

            builder.Phases[index] = new BlazorRazorCSharpLoweringPhase();

            builder.Features.Add(new ConfigureBlazorCodeGenerationOptions());

            builder.Features.Add(new ComponentDocumentClassifierPass());
            builder.Features.Add(new ComponentLoweringPass());

            builder.Features.Add(new ComponentTagHelperDescriptorProvider());

            if (builder.Configuration.ConfigurationName == DeclarationConfiguration.ConfigurationName)
            {
                // This is for 'declaration only' processing. We don't want to try and emit any method bodies during
                // the design time build because we can't do it correctly until the set of components is known.
                builder.Features.Add(new EliminateMethodBodyPass());
            }
        }
Beispiel #2
0
        /// <summary>
        /// Registers the Blazor extension.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        public static void Register(RazorProjectEngineBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            FunctionsDirective.Register(builder);
            ImplementsDirective.Register(builder);
            InheritsDirective.Register(builder);
            InjectDirective.Register(builder);
            LayoutDirective.Register(builder);
            PageDirective.Register(builder);
            TypeParamDirective.Register(builder);

            builder.Features.Remove(builder.Features.OfType <IImportProjectFeature>().Single());
            builder.Features.Add(new BlazorImportProjectFeature());

            var index = builder.Phases.IndexOf(builder.Phases.OfType <IRazorCSharpLoweringPhase>().Single());

            builder.Phases[index] = new BlazorRazorCSharpLoweringPhase();

            builder.Features.Add(new ConfigureBlazorCodeGenerationOptions());

            builder.AddTargetExtension(new BlazorTemplateTargetExtension());

            var isDeclarationOnlyCompile = builder.Configuration.ConfigurationName == DeclarationConfiguration.ConfigurationName;

            // Blazor-specific passes, in order.
            if (!isDeclarationOnlyCompile)
            {
                // There's no benefit in this optimization during the declaration-only compile
                builder.Features.Add(new TrimWhitespacePass());
            }
            builder.Features.Add(new ComponentDocumentClassifierPass());
            builder.Features.Add(new ComponentDocumentRewritePass());
            builder.Features.Add(new ScriptTagPass());
            builder.Features.Add(new ComplexAttributeContentPass());
            builder.Features.Add(new ComponentLoweringPass());
            builder.Features.Add(new EventHandlerLoweringPass());
            builder.Features.Add(new RefLoweringPass());
            builder.Features.Add(new BindLoweringPass());
            builder.Features.Add(new TemplateDiagnosticPass());
            builder.Features.Add(new GenericComponentPass());
            builder.Features.Add(new ChildContentDiagnosticPass());
            builder.Features.Add(new HtmlBlockPass());

            builder.Features.Add(new ComponentTagHelperDescriptorProvider());
            builder.Features.Add(new BindTagHelperDescriptorProvider());
            builder.Features.Add(new EventHandlerTagHelperDescriptorProvider());
            builder.Features.Add(new RefTagHelperDescriptorProvider());

            if (isDeclarationOnlyCompile)
            {
                // This is for 'declaration only' processing. We don't want to try and emit any method bodies during
                // the design time build because we can't do it correctly until the set of components is known.
                builder.Features.Add(new EliminateMethodBodyPass());
            }
        }