diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs index 1bffd6c1e3..fe2c6e92b2 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultDirectiveSyntaxTreePass.cs @@ -1,19 +1,28 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Linq; using Microsoft.AspNetCore.Razor.Language.Legacy; namespace Microsoft.AspNetCore.Razor.Language { - internal class DefaultDirectiveSyntaxTreePass : IRazorSyntaxTreePass + internal class DefaultDirectiveSyntaxTreePass : RazorEngineFeatureBase, IRazorSyntaxTreePass { - public RazorEngine Engine { get; set; } - public int Order => 75; public RazorSyntaxTree Execute(RazorCodeDocument codeDocument, RazorSyntaxTree syntaxTree) { + if (codeDocument == null) + { + throw new ArgumentNullException(nameof(codeDocument)); + } + + if (syntaxTree == null) + { + throw new ArgumentNullException(nameof(syntaxTree)); + } + var errorSink = new ErrorSink(); var sectionVerifier = new NestedSectionVerifier(); sectionVerifier.Verify(syntaxTree, errorSink); diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultDocumentClassifierPassFeature.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultDocumentClassifierPassFeature.cs index b67ac38aac..8890a75cc8 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultDocumentClassifierPassFeature.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultDocumentClassifierPassFeature.cs @@ -7,10 +7,8 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Razor.Language { - internal class DefaultDocumentClassifierPassFeature : IRazorEngineFeature + internal class DefaultDocumentClassifierPassFeature : RazorEngineFeatureBase { - public RazorEngine Engine { get; set; } - public IList> ConfigureClass { get; } = new List>(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs index 8e23fd642b..3a6407e8c1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorCSharpLoweringPhase.cs @@ -18,10 +18,10 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var irDocument = codeDocument.GetIRDocument(); - ThrowForMissingDependency(irDocument); + ThrowForMissingDocumentDependency(irDocument); var syntaxTree = codeDocument.GetSyntaxTree(); - ThrowForMissingDependency(syntaxTree); + ThrowForMissingDocumentDependency(syntaxTree); var target = irDocument.Target; if (target == null) diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveClassifierPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveClassifierPhase.cs index cf1fec6045..9782b54dda 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveClassifierPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveClassifierPhase.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var irDocument = codeDocument.GetIRDocument(); - ThrowForMissingDependency(irDocument); + ThrowForMissingDocumentDependency(irDocument); foreach (var pass in Passes) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveFeature.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveFeature.cs index 7e7e1beafb..bad74c8ecc 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveFeature.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDirectiveFeature.cs @@ -1,20 +1,24 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language { - internal class DefaultRazorDirectiveFeature : IRazorDirectiveFeature, IRazorParserOptionsFeature + internal class DefaultRazorDirectiveFeature : RazorEngineFeatureBase, IRazorDirectiveFeature, IRazorParserOptionsFeature { public ICollection Directives { get; } = new List(); - public RazorEngine Engine { get; set; } - public int Order => 100; void IRazorParserOptionsFeature.Configure(RazorParserOptions options) { + if (options == null) + { + throw new ArgumentNullException(nameof(options)); + } + options.Directives.Clear(); foreach (var directive in Directives) diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDocumentClassifierPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDocumentClassifierPhase.cs index a1c5c24bd3..5fce32c3e1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDocumentClassifierPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorDocumentClassifierPhase.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var irDocument = codeDocument.GetIRDocument(); - ThrowForMissingDependency(irDocument); + ThrowForMissingDocumentDependency(irDocument); foreach (var pass in Passes) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs index fb1ed0457b..18a62a291c 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIRLoweringPhase.cs @@ -15,7 +15,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var syntaxTree = codeDocument.GetSyntaxTree(); - ThrowForMissingDependency(syntaxTree); + ThrowForMissingDocumentDependency(syntaxTree); // This might not have been set if there are no tag helpers. var tagHelperContext = codeDocument.GetTagHelperContext(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIROptimizationPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIROptimizationPhase.cs index 129e09c957..1432bdfe70 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIROptimizationPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorIROptimizationPhase.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var irDocument = codeDocument.GetIRDocument(); - ThrowForMissingDependency(irDocument); + ThrowForMissingDocumentDependency(irDocument); foreach (var pass in Passes) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorSyntaxTreePhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorSyntaxTreePhase.cs index 3bb4442969..5c0df33dfb 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorSyntaxTreePhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorSyntaxTreePhase.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var syntaxTree = codeDocument.GetSyntaxTree(); - ThrowForMissingDependency(syntaxTree); + ThrowForMissingDocumentDependency(syntaxTree); foreach (var pass in Passes) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTagHelperBinderPhase.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTagHelperBinderPhase.cs index 3f00a2b062..6221179257 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTagHelperBinderPhase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTagHelperBinderPhase.cs @@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected override void ExecuteCore(RazorCodeDocument codeDocument) { var syntaxTree = codeDocument.GetSyntaxTree(); - ThrowForMissingDependency(syntaxTree); + ThrowForMissingDocumentDependency(syntaxTree); var resolver = Engine.Features.OfType().FirstOrDefault()?.Resolver; if (resolver == null) diff --git a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTargetExtensionFeature.cs b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTargetExtensionFeature.cs index cccf0f567a..076dac88a1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTargetExtensionFeature.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DefaultRazorTargetExtensionFeature.cs @@ -6,10 +6,8 @@ using Microsoft.AspNetCore.Razor.Language.CodeGeneration; namespace Microsoft.AspNetCore.Razor.Language { - internal class DefaultRazorTargetExtensionFeature : IRazorTargetExtensionFeature + internal class DefaultRazorTargetExtensionFeature : RazorEngineFeatureBase, IRazorTargetExtensionFeature { - public RazorEngine Engine { get; set; } - public ICollection TargetExtensions { get; } = new List(); } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/DesignTimeParserOptionsFeature.cs b/src/Microsoft.AspNetCore.Razor.Language/DesignTimeParserOptionsFeature.cs index 60e494e4cf..736ad20313 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DesignTimeParserOptionsFeature.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DesignTimeParserOptionsFeature.cs @@ -3,10 +3,8 @@ namespace Microsoft.AspNetCore.Razor.Language { - internal class DesignTimeParserOptionsFeature : IRazorParserOptionsFeature + internal class DesignTimeParserOptionsFeature : RazorEngineFeatureBase, IRazorParserOptionsFeature { - public RazorEngine Engine { get; set; } - public int Order { get; set; } public void Configure(RazorParserOptions options) diff --git a/src/Microsoft.AspNetCore.Razor.Language/DocumentClassifierPassBase.cs b/src/Microsoft.AspNetCore.Razor.Language/DocumentClassifierPassBase.cs index 907a3381a2..fa871044e0 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/DocumentClassifierPassBase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/DocumentClassifierPassBase.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language protected ICodeTargetExtension[] TargetExtensions { get; private set; } - protected override void OnIntialized() + protected override void OnInitialized() { var feature = Engine.Features.OfType(); diff --git a/src/Microsoft.AspNetCore.Razor.Language/HtmlNodeOptimizationPass.cs b/src/Microsoft.AspNetCore.Razor.Language/HtmlNodeOptimizationPass.cs index b434e0e204..ea3d754554 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/HtmlNodeOptimizationPass.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/HtmlNodeOptimizationPass.cs @@ -1,18 +1,27 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using Microsoft.AspNetCore.Razor.Language.Legacy; namespace Microsoft.AspNetCore.Razor.Language { - internal class HtmlNodeOptimizationPass : IRazorSyntaxTreePass + internal class HtmlNodeOptimizationPass : RazorEngineFeatureBase, IRazorSyntaxTreePass { - public RazorEngine Engine { get; set; } - public int Order => 100; public RazorSyntaxTree Execute(RazorCodeDocument codeDocument, RazorSyntaxTree syntaxTree) { + if (codeDocument == null) + { + throw new ArgumentNullException(nameof(codeDocument)); + } + + if (syntaxTree == null) + { + throw new ArgumentNullException(nameof(syntaxTree)); + } + var conditionalAttributeCollapser = new ConditionalAttributeCollapser(); var rewritten = conditionalAttributeCollapser.Rewrite(syntaxTree.Root); diff --git a/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs b/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs index 79a7fff09f..f302c5b09d 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Properties/Resources.Designer.cs @@ -402,6 +402,20 @@ namespace Microsoft.AspNetCore.Razor.Language internal static string FormatDirectiveDescriptor_InvalidDirectiveName(object p0) => string.Format(CultureInfo.CurrentCulture, GetString("DirectiveDescriptor_InvalidDirectiveName"), p0); + /// + /// The feature must be initialized by setting the '{0}' property. + /// + internal static string FeatureMustBeInitialized + { + get => GetString("FeatureMustBeInitialized"); + } + + /// + /// The feature must be initialized by setting the '{0}' property. + /// + internal static string FormatFeatureMustBeInitialized(object p0) + => string.Format(CultureInfo.CurrentCulture, GetString("FeatureMustBeInitialized"), p0); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorEngineFeatureBase.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorEngineFeatureBase.cs new file mode 100644 index 0000000000..d4186af69f --- /dev/null +++ b/src/Microsoft.AspNetCore.Razor.Language/RazorEngineFeatureBase.cs @@ -0,0 +1,69 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using System.Linq; + +namespace Microsoft.AspNetCore.Razor.Language +{ + public abstract class RazorEngineFeatureBase : IRazorEngineFeature + { + private RazorEngine _engine; + + public RazorEngine Engine + { + get { return _engine; } + set + { + if (value == null) + { + throw new ArgumentNullException(nameof(value)); + } + + _engine = value; + OnInitialized(); + } + } + + protected T GetRequiredFeature() where T : IRazorEngineFeature + { + if (Engine == null) + { + throw new InvalidOperationException(Resources.FormatFeatureMustBeInitialized(nameof(Engine))); + } + + var feature = Engine.Features.OfType().FirstOrDefault(); + ThrowForMissingEngineDependency(feature); + + return feature; + } + + protected void ThrowForMissingDocumentDependency(TDocumentDependency value) + { + if (value == null) + { + throw new InvalidOperationException( + Resources.FormatFeatureDependencyMissing( + GetType().Name, + typeof(TDocumentDependency).Name, + typeof(RazorCodeDocument).Name)); + } + } + + protected void ThrowForMissingEngineDependency(TEngineDependency value) + { + if (value == null) + { + throw new InvalidOperationException( + Resources.FormatFeatureDependencyMissing( + GetType().Name, + typeof(TEngineDependency).Name, + typeof(RazorEngine).Name)); + } + } + + protected virtual void OnInitialized() + { + } + } +} diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorEnginePhaseBase.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorEnginePhaseBase.cs index 01945fa419..fd87a1a3d1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/RazorEnginePhaseBase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/RazorEnginePhaseBase.cs @@ -2,10 +2,11 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Linq; namespace Microsoft.AspNetCore.Razor.Language { - internal abstract class RazorEnginePhaseBase : IRazorEnginePhase + public abstract class RazorEnginePhaseBase : IRazorEnginePhase { private RazorEngine _engine; @@ -39,14 +40,40 @@ namespace Microsoft.AspNetCore.Razor.Language ExecuteCore(codeDocument); } - protected void ThrowForMissingDependency(T value) + protected T GetRequiredFeature() + { + if (Engine == null) + { + throw new InvalidOperationException(Resources.FormatFeatureMustBeInitialized(nameof(Engine))); + } + + var feature = Engine.Features.OfType().FirstOrDefault(); + ThrowForMissingEngineDependency(feature); + + return feature; + } + + protected void ThrowForMissingDocumentDependency(TDocumentDependency value) { if (value == null) { - throw new InvalidOperationException(Resources.FormatPhaseDependencyMissing( - GetType().Name, - typeof(T).Name, - typeof(RazorCodeDocument).Name)); + throw new InvalidOperationException( + Resources.FormatPhaseDependencyMissing( + GetType().Name, + typeof(TDocumentDependency).Name, + typeof(RazorCodeDocument).Name)); + } + } + + protected void ThrowForMissingEngineDependency(TEngineDependency value) + { + if (value == null) + { + throw new InvalidOperationException( + Resources.FormatPhaseDependencyMissing( + GetType().Name, + typeof(TEngineDependency).Name, + typeof(RazorEngine).Name)); } } diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorIRPassBase.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorIRPassBase.cs index 5474837dfe..bfa5ded760 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/RazorIRPassBase.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/RazorIRPassBase.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Razor.Language.Intermediate; namespace Microsoft.AspNetCore.Razor.Language { - public abstract class RazorIRPassBase + public abstract class RazorIRPassBase : RazorEngineFeatureBase { /// /// The default implementation of the s that run in a @@ -18,53 +18,8 @@ namespace Microsoft.AspNetCore.Razor.Language /// public static readonly int DefaultFeatureOrder = 1000; - private RazorEngine _engine; - - public RazorEngine Engine - { - get { return _engine; } - set - { - if (value == null) - { - throw new ArgumentNullException(nameof(value)); - } - - _engine = value; - OnIntialized(); - } - } - public virtual int Order { get; } - protected void ThrowForMissingDocumentDependency(TDocumentDependency value) - { - if (value == null) - { - throw new InvalidOperationException( - Resources.FormatFeatureDependencyMissing( - GetType().Name, - typeof(TDocumentDependency).Name, - typeof(RazorEngine).Name)); - } - } - - protected void ThrowForMissingEngineDependency(TEngineDependency value) - { - if (value == null) - { - throw new InvalidOperationException( - Resources.FormatFeatureDependencyMissing( - GetType().Name, - typeof(TEngineDependency).Name, - typeof(RazorCodeDocument).Name)); - } - } - - protected virtual void OnIntialized() - { - } - public void Execute(RazorCodeDocument codeDocument, DocumentIRNode irDocument) { if (codeDocument == null) diff --git a/src/Microsoft.AspNetCore.Razor.Language/Resources.resx b/src/Microsoft.AspNetCore.Razor.Language/Resources.resx index 3f9f426265..b372dcd4b1 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Resources.resx +++ b/src/Microsoft.AspNetCore.Razor.Language/Resources.resx @@ -201,4 +201,7 @@ Invalid directive name '{0}'. Directives must have a non-empty name that consists only of letters. + + The feature must be initialized by setting the '{0}' property. + \ No newline at end of file diff --git a/src/Microsoft.CodeAnalysis.Razor/DefaultMetadataReferenceFeature.cs b/src/Microsoft.CodeAnalysis.Razor/DefaultMetadataReferenceFeature.cs index 45a92d7254..7f965e43be 100644 --- a/src/Microsoft.CodeAnalysis.Razor/DefaultMetadataReferenceFeature.cs +++ b/src/Microsoft.CodeAnalysis.Razor/DefaultMetadataReferenceFeature.cs @@ -6,10 +6,8 @@ using Microsoft.AspNetCore.Razor.Language; namespace Microsoft.CodeAnalysis.Razor { - public class DefaultMetadataReferenceFeature : IMetadataReferenceFeature + public class DefaultMetadataReferenceFeature : RazorEngineFeatureBase, IMetadataReferenceFeature { - public RazorEngine Engine { get; set; } - public IReadOnlyList References { get; set; } } } diff --git a/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs b/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs index 16739993c9..16c8f5e7c1 100644 --- a/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs +++ b/src/Microsoft.CodeAnalysis.Razor/DefaultTagHelperFeature.cs @@ -2,37 +2,19 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Collections.Generic; -using System.Linq; using Microsoft.AspNetCore.Razor.Language; using Microsoft.AspNetCore.Razor.Language.Legacy; using Microsoft.CodeAnalysis.CSharp; namespace Microsoft.CodeAnalysis.Razor { - public class DefaultTagHelperFeature : ITagHelperFeature + public class DefaultTagHelperFeature : RazorEngineFeatureBase, ITagHelperFeature { - private RazorEngine _engine; - private IMetadataReferenceFeature _referenceFeature; - - public RazorEngine Engine - { - get - { - return _engine; - } - set - { - _engine = value; - OnInitialized(); - } - } - public ITagHelperDescriptorResolver Resolver { get; private set; } - private void OnInitialized() + protected override void OnInitialized() { - _referenceFeature = Engine.Features.OfType().FirstOrDefault(); - Resolver = new InnerResolver(_referenceFeature); + Resolver = new InnerResolver(GetRequiredFeature()); } private class InnerResolver : ITagHelperDescriptorResolver diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs index 5fc3161c10..8699149f6c 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -562,7 +562,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions.IntegrationTests .Build(); } - private static IRazorEngineFeature GetMetadataReferenceFeature() + private static IMetadataReferenceFeature GetMetadataReferenceFeature() { var currentAssembly = typeof(CodeGenerationIntegrationTest).GetTypeInfo().Assembly; var dependencyContext = DependencyContext.Load(currentAssembly); diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ModelExpressionPassTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ModelExpressionPassTest.cs index 0a22d698f4..e0e9673beb 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ModelExpressionPassTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ModelExpressionPassTest.cs @@ -206,15 +206,13 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions } } - private class TagHelperFeature : ITagHelperFeature + private class TagHelperFeature : RazorEngineFeatureBase, ITagHelperFeature { public TagHelperFeature(TagHelperDescriptor[] tagHelpers) { Resolver = new TagHelperDescriptorResolver(tagHelpers); } - public RazorEngine Engine { get; set; } - public ITagHelperDescriptorResolver Resolver { get; } } diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperPassTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperPassTest.cs index 78d7a29d6a..93dbbf5312 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperPassTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/ViewComponentTagHelperPassTest.cs @@ -364,15 +364,13 @@ public class __Generated__TagCloudViewComponentTagHelper : Microsoft.AspNetCore. } } - private class TagHelperFeature : ITagHelperFeature + private class TagHelperFeature : RazorEngineFeatureBase, ITagHelperFeature { public TagHelperFeature(TagHelperDescriptor[] tagHelpers) { Resolver = new TagHelperDescriptorResolver(tagHelpers); } - public RazorEngine Engine { get; set; } - public ITagHelperDescriptorResolver Resolver { get; } } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs index abfc574c37..0628dc7ae4 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/DefaultRazorParsingPhaseTest.cs @@ -74,10 +74,8 @@ namespace Microsoft.AspNetCore.Razor.Language t => { Assert.Same(t.Source, imports[1]); Assert.Equal("test", Assert.Single(t.Options.Directives).Name); }); } - private class MyParserOptionsFeature : IRazorParserOptionsFeature + private class MyParserOptionsFeature : RazorEngineFeatureBase, IRazorParserOptionsFeature { - public RazorEngine Engine { get; set; } - public int Order { get; } public void Configure(RazorParserOptions options) diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/ParserTestBase.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/ParserTestBase.cs index e73b1664b4..0fcc36b259 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/ParserTestBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/ParserTestBase.cs @@ -52,11 +52,15 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy var root = context.Builder.Build(); var diagnostics = context.ErrorSink.Errors?.Select(error => RazorDiagnostic.Create(error)); - var tree = RazorSyntaxTree.Create(root, source, diagnostics, options); - var defaultDirectivePass = new DefaultDirectiveSyntaxTreePass(); - tree = defaultDirectivePass.Execute(codeDocument: null, syntaxTree: tree); + var codeDocument = RazorCodeDocument.Create(source); - return tree; + var syntaxTree = RazorSyntaxTree.Create(root, source, diagnostics, options); + codeDocument.SetSyntaxTree(syntaxTree); + + var defaultDirectivePass = new DefaultDirectiveSyntaxTreePass(); + syntaxTree = defaultDirectivePass.Execute(codeDocument, syntaxTree); + + return syntaxTree; } internal virtual RazorSyntaxTree ParseHtmlBlock(string document, bool designTime = false) diff --git a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestTagHelperFeature.cs b/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestTagHelperFeature.cs index 507a1d88a1..682fd06d73 100644 --- a/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestTagHelperFeature.cs +++ b/test/Microsoft.AspNetCore.Razor.Test.Common/Langauge/TestTagHelperFeature.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; namespace Microsoft.AspNetCore.Razor.Language { - public class TestTagHelperFeature : ITagHelperFeature + public class TestTagHelperFeature : RazorEngineFeatureBase, ITagHelperFeature { public TestTagHelperFeature() { @@ -18,8 +18,6 @@ namespace Microsoft.AspNetCore.Razor.Language Resolver = new TestTagHelperDescriptorResolver(tagHelpers); } - public RazorEngine Engine { get; set; } - public List TagHelpers => ((TestTagHelperDescriptorResolver)Resolver).TagHelpers; public ITagHelperDescriptorResolver Resolver { get; }