Add support for non-numeric CSharpLanguageVersions.
- We would default to improper C# language versions when given non-numeric `LangVersion`s. For instance when given `CSharpLanguageVersion.Latest` we'd default to 7.3 which was inconsistent with how the rest of the C# world functioned.
- Added a test.
aspnet/AspNetCoredotnet/aspnetcore-tooling#11139
\n\nCommit migrated from a08d0b0673
This commit is contained in:
parent
5ea6ba40cd
commit
ccf56256d9
|
|
@ -32,12 +32,15 @@ namespace Microsoft.CodeAnalysis.Razor
|
|||
builder.Features.Remove(existingFeature);
|
||||
}
|
||||
|
||||
builder.Features.Add(new ConfigureParserForCSharpVersionFeature(csharpLanguageVersion));
|
||||
// This will convert any "latest", "default" or "LatestMajor" LanguageVersions into their numerical equivalent.
|
||||
var effectiveCSharpLanguageVersion = LanguageVersionFacts.MapSpecifiedToEffectiveVersion(csharpLanguageVersion);
|
||||
builder.Features.Add(new ConfigureParserForCSharpVersionFeature(effectiveCSharpLanguageVersion));
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
private class ConfigureParserForCSharpVersionFeature : IConfigureRazorCodeGenerationOptionsFeature
|
||||
// Internal for testing
|
||||
internal class ConfigureParserForCSharpVersionFeature : IConfigureRazorCodeGenerationOptionsFeature
|
||||
{
|
||||
public ConfigureParserForCSharpVersionFeature(LanguageVersion csharpLanguageVersion)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
// 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.Linq;
|
||||
using Microsoft.AspNetCore.Razor.Language;
|
||||
using Xunit;
|
||||
using static Microsoft.CodeAnalysis.Razor.RazorProjectEngineBuilderExtensions;
|
||||
|
||||
namespace Microsoft.CodeAnalysis.Razor
|
||||
{
|
||||
public class RazorProjectEngineBuilderExtensionsTest
|
||||
{
|
||||
[Fact]
|
||||
public void SetCSharpLanguageVersion_ResolvesNonNumericCSharpLangVersions()
|
||||
{
|
||||
// Arrange
|
||||
var csharpLanguageVersion = CSharp.LanguageVersion.Latest;
|
||||
|
||||
// Act
|
||||
var projectEngine = RazorProjectEngine.Create(builder =>
|
||||
{
|
||||
builder.SetCSharpLanguageVersion(csharpLanguageVersion);
|
||||
});
|
||||
|
||||
// Assert
|
||||
var feature = projectEngine.EngineFeatures.OfType<ConfigureParserForCSharpVersionFeature>().FirstOrDefault();
|
||||
Assert.NotNull(feature);
|
||||
Assert.NotEqual(csharpLanguageVersion, feature.CSharpLanguageVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue