コード例 #1
0
        /// <summary>
        /// Sets the root namespace for the generated code.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="rootNamespace">The root namespace.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder SetRootNamespace(this RazorProjectEngineBuilder builder, string rootNamespace)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Features.Add(new ConfigureRootNamespaceFeature(rootNamespace));
            return(builder);
        }
コード例 #2
0
        private static void AddEngineFeaturesAndPhases(RazorProjectEngineBuilder builder, IReadOnlyList <IRazorEngineFeature> engineFeatures)
        {
            for (var i = 0; i < engineFeatures.Count; i++)
            {
                var engineFeature = engineFeatures[i];
                builder.Features.Add(engineFeature);
            }

            RazorEngine.AddDefaultPhases(builder.Phases);
        }
コード例 #3
0
        /// <summary>
        /// Sets the SupportLocalizedComponentNames property to make localized component name diagnostics available.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder SetSupportLocalizedComponentNames(this RazorProjectEngineBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Features.Add(new SetSupportLocalizedComponentNamesFeature());
            return(builder);
        }
コード例 #4
0
        /// <summary>
        /// Adds the provided <see cref="RazorProjectItem" />s as imports to all project items processed
        /// by the <see cref="RazorProjectEngine"/>.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="imports">The collection of imports.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder AddDefaultImports(this RazorProjectEngineBuilder builder, params string[] imports)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Features.Add(new AdditionalImportsProjectFeature(imports));

            return(builder);
        }
コード例 #5
0
        /// <summary>
        /// Sets the namespace for generated types.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="namespaceName">The name of the namespace.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder SetNamespace(this RazorProjectEngineBuilder builder, string namespaceName)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var configurationFeature = GetDefaultDocumentClassifierPassFeature(builder);

            configurationFeature.ConfigureNamespace.Add((document, @namespace) => @namespace.Content = namespaceName);
            return(builder);
        }
コード例 #6
0
ファイル: RazorProjectEngine.cs プロジェクト: wulinacha/Razor
 private static void LoadExtensions(RazorProjectEngineBuilder builder, IReadOnlyList <RazorExtension> extensions)
 {
     for (var i = 0; i < extensions.Count; i++)
     {
         // For now we only handle AssemblyExtension - which is not user-constructable. We're keeping a tight
         // lid on how things work until we add official support for extensibility everywhere. So, this is
         // intentionally inflexible for the time being.
         var extension   = extensions[i] as AssemblyExtension;
         var initializer = extension?.CreateInitializer();
         initializer?.Initialize(builder);
     }
 }
コード例 #7
0
        private static IRazorDirectiveFeature GetDirectiveFeature(RazorProjectEngineBuilder builder)
        {
            var directiveFeature = builder.Features.OfType <IRazorDirectiveFeature>().FirstOrDefault();

            if (directiveFeature == null)
            {
                directiveFeature = new DefaultRazorDirectiveFeature();
                builder.Features.Add(directiveFeature);
            }

            return(directiveFeature);
        }
コード例 #8
0
        /// <summary>
        /// Sets the base type for generated types.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="baseType">The name of the base type.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder SetBaseType(this RazorProjectEngineBuilder builder, string baseType)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var configurationFeature = GetDefaultDocumentClassifierPassFeature(builder);

            configurationFeature.ConfigureClass.Add((document, @class) => @class.BaseType = baseType);
            return(builder);
        }
コード例 #9
0
        private static IRazorTargetExtensionFeature GetTargetExtensionFeature(RazorProjectEngineBuilder builder)
        {
            var targetExtensionFeature = builder.Features.OfType <IRazorTargetExtensionFeature>().FirstOrDefault();

            if (targetExtensionFeature == null)
            {
                targetExtensionFeature = new DefaultRazorTargetExtensionFeature();
                builder.Features.Add(targetExtensionFeature);
            }

            return(targetExtensionFeature);
        }
コード例 #10
0
        public static RazorProjectEngineBuilder AddTagHelpers(this RazorProjectEngineBuilder builder, IEnumerable <TagHelperDescriptor> tagHelpers)
        {
            var feature = (TestTagHelperFeature)builder.Features.OfType <ITagHelperFeature>().FirstOrDefault();

            if (feature is null)
            {
                feature = new TestTagHelperFeature();
                builder.Features.Add(feature);
            }

            feature.TagHelpers.AddRange(tagHelpers);
            return(builder);
        }
コード例 #11
0
        private static void AddComponentFeatures(RazorProjectEngineBuilder builder, RazorLanguageVersion razorLanguageVersion)
        {
            // Project Engine Features
            builder.Features.Add(new ComponentImportProjectFeature());

            // Directives (conditional on file kind)
            ComponentCodeDirective.Register(builder);
            ComponentInjectDirective.Register(builder);
            ComponentLayoutDirective.Register(builder);
            ComponentPageDirective.Register(builder);



            if (razorLanguageVersion.CompareTo(RazorLanguageVersion.Version_6_0) >= 0)
            {
                ComponentConstrainedTypeParamDirective.Register(builder);
            }
            else
            {
                ComponentTypeParamDirective.Register(builder);
            }

            if (razorLanguageVersion.CompareTo(RazorLanguageVersion.Version_5_0) >= 0)
            {
                ComponentPreserveWhitespaceDirective.Register(builder);
            }

            // Document Classifier
            builder.Features.Add(new ComponentDocumentClassifierPass());

            // Directive Classifier
            builder.Features.Add(new ComponentWhitespacePass());

            // Optimization
            builder.Features.Add(new ComponentComplexAttributeContentPass());
            builder.Features.Add(new ComponentLoweringPass());
            builder.Features.Add(new ComponentScriptTagPass());
            builder.Features.Add(new ComponentEventHandlerLoweringPass());
            builder.Features.Add(new ComponentKeyLoweringPass());
            builder.Features.Add(new ComponentReferenceCaptureLoweringPass());
            builder.Features.Add(new ComponentSplatLoweringPass());
            builder.Features.Add(new ComponentBindLoweringPass());
            builder.Features.Add(new ComponentCssScopePass());
            builder.Features.Add(new ComponentTemplateDiagnosticPass());
            builder.Features.Add(new ComponentGenericTypePass());
            builder.Features.Add(new ComponentChildContentDiagnosticPass());
            builder.Features.Add(new ComponentMarkupDiagnosticPass());
            builder.Features.Add(new ComponentMarkupBlockPass());
            builder.Features.Add(new ComponentMarkupEncodingPass());
        }
コード例 #12
0
        /// <summary>
        /// Adds the provided <see cref="RazorProjectItem" />s as imports to all project items processed
        /// by the <see cref="RazorProjectEngine"/>.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="imports">The collection of imports.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder AddDefaultImports(this RazorProjectEngineBuilder builder, params RazorProjectItem[] imports)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var existingImportFeature = builder.Features.OfType <IImportProjectFeature>().First();
            var testImportFeature     = new AdditionalImportsProjectFeature(existingImportFeature, imports);

            builder.SetImportFeature(testImportFeature);

            return(builder);
        }
コード例 #13
0
        /// <summary>
        /// Adds the specified <see cref="ICodeTargetExtension"/>.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="extension">The <see cref="ICodeTargetExtension"/> to add.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder AddTargetExtension(this RazorProjectEngineBuilder builder, ICodeTargetExtension extension)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (extension == null)
            {
                throw new ArgumentNullException(nameof(extension));
            }

            var targetExtensionFeature = GetTargetExtensionFeature(builder);

            targetExtensionFeature.TargetExtensions.Add(extension);

            return(builder);
        }
コード例 #14
0
        /// <summary>
        /// Adds the specified <see cref="DirectiveDescriptor"/>.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="directive">The <see cref="DirectiveDescriptor"/> to add.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder AddDirective(this RazorProjectEngineBuilder builder, DirectiveDescriptor directive)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (directive == null)
            {
                throw new ArgumentNullException(nameof(directive));
            }

            var directiveFeature = GetDirectiveFeature(builder);

            directiveFeature.Directives.Add(directive);

            return(builder);
        }
コード例 #15
0
        /// <summary>
        /// Registers a class configuration delegate that gets invoked during code generation.
        /// </summary>
        /// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
        /// <param name="configureClass"><see cref="Action"/> invoked to configure
        /// <see cref="ClassDeclarationIntermediateNode"/> during code generation.</param>
        /// <returns>The <see cref="RazorProjectEngineBuilder"/>.</returns>
        public static RazorProjectEngineBuilder ConfigureClass(
            this RazorProjectEngineBuilder builder,
            Action <RazorCodeDocument, ClassDeclarationIntermediateNode> configureClass)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configureClass == null)
            {
                throw new ArgumentNullException(nameof(configureClass));
            }

            var configurationFeature = GetDefaultDocumentClassifierPassFeature(builder);

            configurationFeature.ConfigureClass.Add(configureClass);
            return(builder);
        }
コード例 #16
0
        public static void SetImportFeature(this RazorProjectEngineBuilder builder, IRazorImportFeature feature)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (feature == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Remove any existing import features in favor of the new one we're given.
            var existingFeatures = builder.Features.OfType <IRazorImportFeature>().ToArray();

            foreach (var existingFeature in existingFeatures)
            {
                builder.Features.Remove(existingFeature);
            }

            builder.Features.Add(feature);
        }
コード例 #17
0
        public static RazorProjectEngineBuilder ConfigureDocumentClassifier(this RazorProjectEngineBuilder builder)
        {
            var feature = builder.Features.OfType <DefaultDocumentClassifierPassFeature>().FirstOrDefault();

            if (feature == null)
            {
                feature = new DefaultDocumentClassifierPassFeature();
                builder.Features.Add(feature);
            }

            feature.ConfigureNamespace.Clear();
            feature.ConfigureClass.Clear();
            feature.ConfigureMethod.Clear();

            feature.ConfigureNamespace.Add((RazorCodeDocument codeDocument, NamespaceDeclarationIntermediateNode node) =>
            {
                node.Content = "Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles";
            });

            feature.ConfigureClass.Add((RazorCodeDocument codeDocument, ClassDeclarationIntermediateNode node) =>
            {
                node.ClassName = IntegrationTestBase.FileName.Replace('/', '_');
                node.Modifiers.Clear();
                node.Modifiers.Add("public");
            });

            feature.ConfigureMethod.Add((RazorCodeDocument codeDocument, MethodDeclarationIntermediateNode node) =>
            {
                node.Modifiers.Clear();
                node.Modifiers.Add("public");
                node.Modifiers.Add("async");
                node.MethodName = "ExecuteAsync";
                node.ReturnType = typeof(Task).FullName;
            });

            return(builder);
        }
コード例 #18
0
 private static void AddDefaults(RazorProjectEngineBuilder builder)
 {
     builder.Features.Add(new DefaultRazorImportFeature());
 }
コード例 #19
0
 public static RazorProjectEngineBuilder AddTagHelpers(this RazorProjectEngineBuilder builder, params TagHelperDescriptor[] tagHelpers)
 {
     return(AddTagHelpers(builder, (IEnumerable <TagHelperDescriptor>)tagHelpers));
 }
コード例 #20
0
 protected virtual void ConfigureProjectEngine(RazorProjectEngineBuilder builder)
 {
 }
コード例 #21
0
        private static DefaultDocumentClassifierPassFeature GetDefaultDocumentClassifierPassFeature(RazorProjectEngineBuilder builder)
        {
            var configurationFeature = builder.Features.OfType <DefaultDocumentClassifierPassFeature>().FirstOrDefault();

            if (configurationFeature == null)
            {
                configurationFeature = new DefaultDocumentClassifierPassFeature();
                builder.Features.Add(configurationFeature);
            }

            return(configurationFeature);
        }