Skip to content

Commit

Permalink
RazorProjectEngine: Don't expose EngineFeatures
Browse files Browse the repository at this point in the history
This property isn't necessary. Nearly every caller can be changed to go through RazorProjectEngine.Engine.GetFeatures<T>().
  • Loading branch information
DustinCampbell committed Dec 26, 2024
1 parent 64394f2 commit c728852
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private static DocumentIntermediateNode CreateIRDocument(RazorProjectEngine proj
// We also expect the default tag helper pass to run first.
var documentNode = codeDocument.GetDocumentIntermediateNode();

var defaultTagHelperPass = projectEngine.EngineFeatures.OfType<DefaultTagHelperOptimizationPass>().Single();
var defaultTagHelperPass = projectEngine.Engine.GetFeatures<DefaultTagHelperOptimizationPass>().Single();
defaultTagHelperPass.Execute(codeDocument, documentNode);

return codeDocument.GetDocumentIntermediateNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ private DocumentIntermediateNode CreateIRDocument(RazorProjectEngine projectEngi
// We also expect the default tag helper pass to run first.
var documentNode = codeDocument.GetDocumentIntermediateNode();

var defaultTagHelperPass = projectEngine.EngineFeatures.OfType<DefaultTagHelperOptimizationPass>().Single();
var defaultTagHelperPass = projectEngine.Engine.GetFeatures<DefaultTagHelperOptimizationPass>().Single();
defaultTagHelperPass.Execute(codeDocument, documentNode);

return codeDocument.GetDocumentIntermediateNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static void AssertDefaultPhases(RazorProjectEngine engine)

private static void AssertDefaultFeatures(RazorProjectEngine engine)
{
var features = engine.EngineFeatures.OrderBy(f => f.GetType().Name).ToArray();
var features = engine.Engine.Features.OrderByAsArray(static x => x.GetType().Name);
Assert.Collection(
features,
feature => Assert.IsType<AttributeDirectivePass>(feature),
Expand Down Expand Up @@ -96,7 +96,7 @@ private static void AssertDefaultFeatures(RazorProjectEngine engine)

private static void AssertDefaultDirectives(RazorProjectEngine engine)
{
var feature = engine.EngineFeatures.OfType<IRazorDirectiveFeature>().FirstOrDefault();
var feature = engine.Engine.GetFeatures<IRazorDirectiveFeature>().FirstOrDefault();
Assert.NotNull(feature);
Assert.Collection(
feature.Directives,
Expand All @@ -109,7 +109,7 @@ private static void AssertDefaultDirectives(RazorProjectEngine engine)

private static void AssertDefaultTargetExtensions(RazorProjectEngine engine)
{
var feature = engine.EngineFeatures.OfType<IRazorTargetExtensionFeature>().FirstOrDefault();
var feature = engine.Engine.GetFeatures<IRazorTargetExtensionFeature>().FirstOrDefault();
Assert.NotNull(feature);

var extensions = feature.TargetExtensions.OrderBy(f => f.GetType().Name).ToArray();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System;
using System.Linq;
using System.Collections.Immutable;

namespace Microsoft.AspNetCore.Razor.Language;

internal class DefaultRazorCodeGenerationOptionsFactoryProjectFeature : RazorProjectEngineFeatureBase, IRazorCodeGenerationOptionsFactoryProjectFeature
{
private IConfigureRazorCodeGenerationOptionsFeature[] _configureOptions;
private ImmutableArray<IConfigureRazorCodeGenerationOptionsFeature> _configureOptions;

protected override void OnInitialized()
{
_configureOptions = ProjectEngine.EngineFeatures.OfType<IConfigureRazorCodeGenerationOptionsFeature>().ToArray();
_configureOptions = ProjectEngine.Engine.GetFeatures<IConfigureRazorCodeGenerationOptionsFeature>();
}

public RazorCodeGenerationOptions Create(Action<RazorCodeGenerationOptionsBuilder> configure)
{
var builder = new RazorCodeGenerationOptionsBuilder(ProjectEngine.Configuration);
configure?.Invoke(builder);

for (var i = 0; i < _configureOptions.Length; i++)
foreach (var options in _configureOptions)
{
_configureOptions[i].Configure(builder);
options.Configure(builder);
}

var options = builder.Build();
return options;
return builder.Build();
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable disable

using System;
using System.Linq;
using System.Collections.Immutable;

namespace Microsoft.AspNetCore.Razor.Language;

internal class DefaultRazorParserOptionsFactoryProjectFeature : RazorProjectEngineFeatureBase, IRazorParserOptionsFactoryProjectFeature
{
private IConfigureRazorParserOptionsFeature[] _configureOptions;
private ImmutableArray<IConfigureRazorParserOptionsFeature> _configureOptions;

protected override void OnInitialized()
{
_configureOptions = ProjectEngine.EngineFeatures.OfType<IConfigureRazorParserOptionsFeature>().ToArray();
_configureOptions = ProjectEngine.Engine.GetFeatures<IConfigureRazorParserOptionsFeature>();
}

public RazorParserOptions Create(string fileKind, Action<RazorParserOptionsBuilder> configure)
{
var builder = new RazorParserOptionsBuilder(ProjectEngine.Configuration, fileKind);
configure?.Invoke(builder);

for (var i = 0; i < _configureOptions.Length; i++)
foreach (var options in _configureOptions)
{
_configureOptions[i].Configure(builder);
options.Configure(builder);
}

var options = builder.Build();
return options;
return builder.Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class RazorProjectEngine
public RazorConfiguration Configuration { get; }
public RazorProjectFileSystem FileSystem { get; }
public RazorEngine Engine { get; }
public ImmutableArray<IRazorEngineFeature> EngineFeatures => Engine.Features;
public ImmutableArray<IRazorEnginePhase> Phases => Engine.Phases;
public ImmutableArray<IRazorProjectEngineFeature> ProjectFeatures { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void GetDescriptors_DoesNotSetCompilation_IfCompilationIsInvalid()
configure.Features.Add(new CompilationTagHelperFeature());
});

var feature = engine.EngineFeatures.OfType<CompilationTagHelperFeature>().First();
var feature = engine.Engine.GetFeatures<CompilationTagHelperFeature>().First();

// Act
var result = feature.GetDescriptors();
Expand Down Expand Up @@ -119,7 +119,7 @@ public void GetDescriptors_SetsCompilation_IfCompilationIsValid()
configure.Features.Add(new CompilationTagHelperFeature());
});

var feature = engine.EngineFeatures.OfType<CompilationTagHelperFeature>().First();
var feature = engine.Engine.GetFeatures<CompilationTagHelperFeature>().First();

// Act
var result = feature.GetDescriptors();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void SetCSharpLanguageVersion_ResolvesNonNumericCSharpLangVersions()
});

// Assert
var feature = projectEngine.EngineFeatures.OfType<ConfigureParserForCSharpVersionFeature>().FirstOrDefault();
var feature = projectEngine.Engine.GetFeatures<ConfigureParserForCSharpVersionFeature>().FirstOrDefault();
Assert.NotNull(feature);
Assert.NotEqual(csharpLanguageVersion, feature.CSharpLanguageVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SyntaxTreeGenerationBenchmark()
var projectItem = fileSystem.GetItem(Path.Combine(root.FullName, "MSN.cshtml"), FileKinds.Legacy);
MSN = RazorSourceDocument.ReadFrom(projectItem);

var directiveFeature = ProjectEngine.EngineFeatures.OfType<IRazorDirectiveFeature>().FirstOrDefault();
var directiveFeature = ProjectEngine.Engine.GetFeatures<IRazorDirectiveFeature>().FirstOrDefault();
Directives = directiveFeature?.Directives.ToArray() ?? Array.Empty<DirectiveDescriptor>();
}

Expand Down

0 comments on commit c728852

Please sign in to comment.