diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/InjectDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/InjectDirectiveTest.cs index 98e4fac5b26..9cebad9a134 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/InjectDirectiveTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/InjectDirectiveTest.cs @@ -48,7 +48,7 @@ @inject PropertyType PropertyName Assert.Equal("PropertyType", node.TypeName); Assert.Equal("PropertyName", node.MemberName); } - + [Fact] public void InjectDirectivePass_Execute_DedupesPropertiesByName() { diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs index 01c1f17d866..279da1a4377 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/IntegrationTests/CodeGenerationIntegrationTest.cs @@ -333,6 +333,94 @@ public class MyApp AssertSourceMappingsMatchBaseline(compiled.CodeDocument); } + + [Fact] + public void InjectWithKey_Runtime() + { + // Arrange + AddCSharpSyntaxTree(""" + + public class MyModel + { + + } + + public class MyService + { + public string Html { get; set; } + } + + public class MyApp + { + public string MyProperty { get; set; } + } + """); + + var projectItem = CreateProjectItemFromFile(); + + // Act + var compiled = CompileToAssembly(projectItem, designTime: false); + + // Assert + AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentNode()); + AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument()); + AssertLinePragmas(compiled.CodeDocument); + } + + + + + [Fact] + public void MixKeyedInject_Runtime() + { + // Arrange + AddCSharpSyntaxTree(""" + + public class MyModel + { + + } + + public class MyService + { + public string Html { get; set; } + } + + public class MyApp + { + public string MyProperty { get; set; } + } + """); + + var projectItem = CreateProjectItemFromFile(); + + // Act + var compiled = CompileToAssembly(projectItem, designTime: false); + + // Assert + AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentNode()); + AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument()); + AssertLinePragmas(compiled.CodeDocument); + } + + [Fact] + public void MalformedKeyedInject_Runtime() + { + // Arrange + var projectItem = CreateProjectItemFromFile(); + + // Act + var compiled = CompileToCSharp(projectItem, designTime: false); + + // Assert + AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentNode()); + AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument()); + AssertLinePragmas(compiled.CodeDocument); + + var diagnotics = compiled.CodeDocument.GetCSharpDocument().Diagnostics; + Assert.Equal("RZ1016", Assert.Single(diagnotics).Id); + } + [Fact] public void InjectWithSemicolon_Runtime() { @@ -1255,6 +1343,96 @@ public class MyApp AssertSourceMappingsMatchBaseline(compiled.CodeDocument); } + + [Fact] + public void InjectWithKey_DesignTime() + { + // Arrange + AddCSharpSyntaxTree(""" + + public class MyModel + { + + } + + public class MyService + { + public string Html { get; set; } + } + + public class MyApp + { + public string MyProperty { get; set; } + } + """); + + var projectItem = CreateProjectItemFromFile(); + + // Act + var compiled = CompileToAssembly(projectItem, designTime: true); + + // Assert + AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentNode()); + AssertHtmlDocumentMatchesBaseline(RazorHtmlWriter.GetHtmlDocument(compiled.CodeDocument)); + AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument()); + AssertLinePragmas(compiled.CodeDocument); + AssertSourceMappingsMatchBaseline(compiled.CodeDocument); + } + + [Fact] + public void MalformedKeyedInject_DesignTime() + { + // Arrange + var projectItem = CreateProjectItemFromFile(); + + // Act + var compiled = CompileToCSharp(projectItem, designTime: true); + + // Assert + AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentNode()); + AssertHtmlDocumentMatchesBaseline(RazorHtmlWriter.GetHtmlDocument(compiled.CodeDocument)); + AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument()); + AssertLinePragmas(compiled.CodeDocument); + AssertSourceMappingsMatchBaseline(compiled.CodeDocument); + + var diagnotics = compiled.CodeDocument.GetCSharpDocument().Diagnostics; + Assert.Equal("RZ1016", Assert.Single(diagnotics).Id); + } + + [Fact] + public void MixKeyedInject_DesignTime() + { + // Arrange + AddCSharpSyntaxTree(""" + + public class MyModel + { + + } + + public class MyService + { + public string Html { get; set; } + } + + public class MyApp + { + public string MyProperty { get; set; } + } + """); + + var projectItem = CreateProjectItemFromFile(); + + // Act + var compiled = CompileToAssembly(projectItem, designTime: true); + + // Assert + AssertDocumentNodeMatchesBaseline(compiled.CodeDocument.GetDocumentNode()); + AssertHtmlDocumentMatchesBaseline(RazorHtmlWriter.GetHtmlDocument(compiled.CodeDocument)); + AssertCSharpDocumentMatchesBaseline(compiled.CodeDocument.GetCSharpDocument()); + AssertLinePragmas(compiled.CodeDocument); + AssertSourceMappingsMatchBaseline(compiled.CodeDocument); + } [Fact] public void InjectWithSemicolon_DesignTime() { diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/KeyedInjectDirectiveTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/KeyedInjectDirectiveTest.cs new file mode 100644 index 00000000000..c04324a2f97 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/KeyedInjectDirectiveTest.cs @@ -0,0 +1,152 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; + +public class KeyedInjectDirectiveTest : RazorProjectEngineTestBase +{ + protected override RazorLanguageVersion Version => RazorLanguageVersion.Version_3_0; + + protected override void ConfigureProjectEngine(RazorProjectEngineBuilder builder) + { + // Notice we're not registering the InjectDirective.Pass here so we can run it on demand. + builder.AddDirective(InjectDirective.Directive); + builder.AddDirective(KeyedInjectDirective.Directive); + builder.AddDirective(ModelDirective.Directive); + + builder.Features.Add(new RazorPageDocumentClassifierPass()); + builder.Features.Add(new MvcViewDocumentClassifierPass()); + } + + protected override void ConfigureCodeDocumentProcessor(RazorCodeDocumentProcessor processor) + { + processor.ExecutePhasesThrough(); + } + + [Fact] + public void KeyedInjectDirectivePass_Execute_DefinesProperty() + { + // Arrange + var codeDocument = ProjectEngine.CreateCodeDocument(@" +@keyedinject PropertyType PropertyName ""PropertyKey"" +"); + var processor = CreateCodeDocumentProcessor(codeDocument); + + // Act + processor.ExecutePass(); + + // Assert + var documentNode = processor.GetDocumentNode(); + var classNode = documentNode.GetClassNode(); + + Assert.Equal(2, classNode.Children.Count); + + var node = Assert.IsType(classNode.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + Assert.Equal("\"PropertyKey\"", node.KeyName); + } + + [Fact] + public void KeyedInjectDirectivePass_Execute_DedupesPropertiesByName() + { + // Arrange + var codeDocument = ProjectEngine.CreateCodeDocument(@" +@keyedinject PropertyType PropertyName ""SomeKey"" +@keyedinject PropertyType2 PropertyName ""SomeKey2"" +"); + var processor = CreateCodeDocumentProcessor(codeDocument); + + // Act + processor.ExecutePass(); + + // Assert + var documentNode = processor.GetDocumentNode(); + var classNode = documentNode.GetClassNode(); + + Assert.Equal(2, classNode.Children.Count); + + var node = Assert.IsType(classNode.Children[1]); + Assert.Equal("PropertyType2", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + Assert.Equal("\"SomeKey2\"", node.KeyName); + } + + [Fact] + public void KeyedInjectDirectivePass_Execute_ExpandsTModel_WithDynamic() + { + // Arrange + var codeDocument = ProjectEngine.CreateCodeDocument(@" +@keyedinject PropertyType PropertyName ""SomeKey"" +"); + var processor = CreateCodeDocumentProcessor(codeDocument); + + // Act + processor.ExecutePass(); + + // Assert + var documentNode = processor.GetDocumentNode(); + var classNode = documentNode.GetClassNode(); + + Assert.Equal(2, classNode.Children.Count); + + var node = Assert.IsType(classNode.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + Assert.Equal("\"SomeKey\"", node.KeyName); + } + + [Fact] + public void KeyedInjectDirectivePass_Execute_ExpandsTModel_WithModelTypeFirst() + { + // Arrange + var codeDocument = ProjectEngine.CreateCodeDocument(@" +@model ModelType +@keyedinject PropertyType PropertyName ""SomeKey"" +"); + var processor = CreateCodeDocumentProcessor(codeDocument); + + // Act + processor.ExecutePass(); + + // Assert + var documentNode = processor.GetDocumentNode(); + var classNode = documentNode.GetClassNode(); + + Assert.Equal(2, classNode.Children.Count); + + var node = Assert.IsType(classNode.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + Assert.Equal("\"SomeKey\"", node.KeyName); + } + + [Fact] + public void KeyedInjectDirectivePass_Execute_ExpandsTModel_WithModelType() + { + // Arrange + var codeDocument = ProjectEngine.CreateCodeDocument(@" +@keyedinject PropertyType PropertyName ""SomeKey"" +@model ModelType +"); + var processor = CreateCodeDocumentProcessor(codeDocument); + + // Act + processor.ExecutePass(); + + // Assert + var documentNode = processor.GetDocumentNode(); + var classNode = documentNode.GetClassNode(); + + Assert.Equal(2, classNode.Children.Count); + + var node = Assert.IsType(classNode.Children[1]); + Assert.Equal("PropertyType", node.TypeName); + Assert.Equal("PropertyName", node.MemberName); + Assert.Equal("\"SomeKey\"", node.KeyName); + } +} diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/KeyedInjectTargetExtensionTest.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/KeyedInjectTargetExtensionTest.cs new file mode 100644 index 00000000000..9c40d276215 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/KeyedInjectTargetExtensionTest.cs @@ -0,0 +1,45 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Microsoft.AspNetCore.Razor.Language.Legacy; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; + +public class KeyedInjectTargetExtensionTest +{ + + [Fact] + public void KeyedInjectDirectiveTargetExtension_WritesProperty() + { + // Arrange + using var context = TestCodeRenderingContext.CreateRuntime(); + var target = new KeyedInjectTargetExtension(considerNullabilityEnforcement: true); + var node = new KeyedInjectIntermediateNode() + { + TypeName = "PropertyType", + MemberName = "PropertyName", + KeyName = "\"PropertyKey\"", + }; + + // Act + target.WriteKeyedInjectProperty(context, node); + + // Assert + Assert.Equal(""" + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "PropertyKey")] + public PropertyType PropertyName { get; private set; } = default!; + #nullable disable + + """, + context.CodeWriter.GetText().ToString()); + } + +} diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml new file mode 100644 index 00000000000..f4a64bd21f6 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml @@ -0,0 +1,5 @@ +@model MyModel +@keyedinject MyApp MyPropertyName "KeyOne" +@keyedinject MyService Html "KeyOne" +@keyedinject MyApp MyPropertyName2 "SomeKey" ; +@keyedinject MyService Html2 "SomeKey" ; diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.codegen.cs new file mode 100644 index 00000000000..6887194898e --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.codegen.cs @@ -0,0 +1,198 @@ +// +#pragma warning disable 1591 +namespace AspNetCoreGeneratedDocument +{ + #line default + using TModel = global::System.Object; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithKey : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyModel __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object MyPropertyName = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object __typeHelper = "KeyOne"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyService __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object Html = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object __typeHelper = "KeyOne"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 4 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 4 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object MyPropertyName2 = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 4 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object __typeHelper = "SomeKey"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyService __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object Html2 = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +global::System.Object __typeHelper = "SomeKey"; + +#line default +#line hidden +#nullable disable + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "SomeKey")] + public MyService Html2 { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "SomeKey")] + public MyApp MyPropertyName2 { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "KeyOne")] + public MyApp MyPropertyName { get; private set; } = default!; + #nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.codegen.html b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.codegen.html new file mode 100644 index 00000000000..0c00766321c --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.codegen.html @@ -0,0 +1,5 @@ +/*~~*/ /*~~~*/ +/*~~~~~~~~*/ /*~*/ /*~~~~~~~~~~*/ /*~~~~*/ +/*~~~~~~~~*/ /*~~~~~~~~~~~~~*/ /**/ /*~~~~*/ +/*~~~~~~~~*/ /*~*/ /*~~~~~~~~~~~*/ /*~~~~~*/ ~ +/*~~~~~~~~*/ /*~~~~~~~~~~~~~*/ /*~*/ /*~~~~~*/ ~ diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.ir.txt new file mode 100644 index 00000000000..7647f1beb9f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.ir.txt @@ -0,0 +1,55 @@ +Document - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithKey - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (287:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (350:7,71 [4] ) - Html + DirectiveToken - (364:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (419:8,63 [4] ) - Json + DirectiveToken - (433:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (487:9,62 [9] ) - Component + DirectiveToken - (506:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (550:10,52 [3] ) - Url + DirectiveToken - (563:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (634:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (673:12,14 [104] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (793:13,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (904:14,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [7] InjectWithKey.cshtml) - MyModel + DirectiveToken - (29:1,13 [5] InjectWithKey.cshtml) - MyApp + DirectiveToken - (35:1,19 [14] InjectWithKey.cshtml) - MyPropertyName + DirectiveToken - (51:1,35 [8] InjectWithKey.cshtml) - "KeyOne" + DirectiveToken - (74:2,13 [17] InjectWithKey.cshtml) - MyService + DirectiveToken - (92:2,31 [4] InjectWithKey.cshtml) - Html + DirectiveToken - (97:2,36 [8] InjectWithKey.cshtml) - "KeyOne" + DirectiveToken - (120:3,13 [5] InjectWithKey.cshtml) - MyApp + DirectiveToken - (126:3,19 [15] InjectWithKey.cshtml) - MyPropertyName2 + DirectiveToken - (142:3,35 [9] InjectWithKey.cshtml) - "SomeKey" + DirectiveToken - (168:4,13 [17] InjectWithKey.cshtml) - MyService + DirectiveToken - (186:4,31 [5] InjectWithKey.cshtml) - Html2 + DirectiveToken - (192:4,37 [9] InjectWithKey.cshtml) - "SomeKey" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + KeyedInject - + KeyedInject - + KeyedInject - diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.mappings.txt new file mode 100644 index 00000000000..97114ac3f15 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_DesignTime.mappings.txt @@ -0,0 +1,65 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyModel| +Generated Location: (1218:26,0 [7] ) +|MyModel| + +Source Location: (29:1,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyApp| +Generated Location: (1478:36,0 [5] ) +|MyApp| + +Source Location: (35:1,19 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyPropertyName| +Generated Location: (1758:46,22 [14] ) +|MyPropertyName| + +Source Location: (51:1,35 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|"KeyOne"| +Generated Location: (2046:56,37 [8] ) +|"KeyOne"| + +Source Location: (74:2,13 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyService| +Generated Location: (2283:66,0 [17] ) +|MyService| + +Source Location: (92:2,31 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|Html| +Generated Location: (2575:76,22 [4] ) +|Html| + +Source Location: (97:2,36 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|"KeyOne"| +Generated Location: (2853:86,37 [8] ) +|"KeyOne"| + +Source Location: (120:3,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyApp| +Generated Location: (3090:96,0 [5] ) +|MyApp| + +Source Location: (126:3,19 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyPropertyName2| +Generated Location: (3370:106,22 [15] ) +|MyPropertyName2| + +Source Location: (142:3,35 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|"SomeKey"| +Generated Location: (3659:116,37 [9] ) +|"SomeKey"| + +Source Location: (168:4,13 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyService| +Generated Location: (3897:126,0 [17] ) +|MyService| + +Source Location: (186:4,31 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|Html2| +Generated Location: (4189:136,22 [5] ) +|Html2| + +Source Location: (192:4,37 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|"SomeKey"| +Generated Location: (4468:146,37 [9] ) +|"SomeKey"| + diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.codegen.cs new file mode 100644 index 00000000000..69d9d83df78 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.codegen.cs @@ -0,0 +1,116 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "d201ecac63a18768701926f12ca75703f61ae21a3fac9eee4ae94b14be150e27" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithKey), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml")] +namespace AspNetCoreGeneratedDocument +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"d201ecac63a18768701926f12ca75703f61ae21a3fac9eee4ae94b14be150e27", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml")] + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithKey : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyModel + +#line default +#line hidden +#nullable disable + > + #nullable disable + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "SomeKey")] + public +#nullable restore +#line (5,14)-(5,23) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyService + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (5,32)-(5,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +Html2 + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "SomeKey")] + public +#nullable restore +#line (4,14)-(4,19) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyApp + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (4,20)-(4,35) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyPropertyName2 + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "KeyOne")] + public +#nullable restore +#line (2,14)-(2,19) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyApp + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (2,20)-(2,34) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml" +MyPropertyName + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.ir.txt new file mode 100644 index 00000000000..63cd065ed9d --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.ir.txt @@ -0,0 +1,23 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_InjectWithKey - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + KeyedInject - + KeyedInject - + KeyedInject - diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.mappings.txt new file mode 100644 index 00000000000..7a2f78f2aee --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey_Runtime.mappings.txt @@ -0,0 +1,35 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyModel| +Generated Location: (1751:23,0 [7] ) +|MyModel| + +Source Location: (168:4,13 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyService| +Generated Location: (3517:60,0 [9] ) +|MyService| + +Source Location: (186:4,31 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|Html2| +Generated Location: (3718:68,0 [5] ) +|Html2| + +Source Location: (120:3,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyApp| +Generated Location: (4063:79,0 [5] ) +|MyApp| + +Source Location: (126:3,19 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyPropertyName2| +Generated Location: (4251:87,0 [15] ) +|MyPropertyName2| + +Source Location: (29:1,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyApp| +Generated Location: (4605:98,0 [5] ) +|MyApp| + +Source Location: (35:1,19 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithKey.cshtml) +|MyPropertyName| +Generated Location: (4793:106,0 [14] ) +|MyPropertyName| + diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt index cb492a0fcca..bbbf2007e9c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon_DesignTime.mappings.txt @@ -1,4 +1,4 @@ -Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/InjectWithSemicolon.cshtml) |MyModel| Generated Location: (1236:26,0 [7] ) |MyModel| diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml new file mode 100644 index 00000000000..09ae006bb44 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml @@ -0,0 +1,2 @@ +@model MyModel +@keyedinject MyApp MyPropertyName "KeyOne diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.codegen.cs new file mode 100644 index 00000000000..c6df967a9f7 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.codegen.cs @@ -0,0 +1,86 @@ +// +#pragma warning disable 1591 +namespace AspNetCoreGeneratedDocument +{ + #line default + using TModel = global::System.Object; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MalformedKeyedInject : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" +MyModel __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" +global::System.Object MyPropertyName = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.codegen.html b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.codegen.html new file mode 100644 index 00000000000..fbd71d01ad2 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.codegen.html @@ -0,0 +1,2 @@ +/*~~*/ /*~~~*/ +/*~~~~~~~~*/ /*~*/ /*~~~~~~~~~~*/ "KeyOne diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.diagnostics.txt new file mode 100644 index 00000000000..77970f18d15 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.diagnostics.txt @@ -0,0 +1 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml(2,35): Error RZ1016: The 'keyedinject' directive expects a string surrounded by double quotes. diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.ir.txt new file mode 100644 index 00000000000..678b7199aee --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.ir.txt @@ -0,0 +1,48 @@ +Document - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MalformedKeyedInject - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (287:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (350:7,71 [4] ) - Html + DirectiveToken - (364:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (419:8,63 [4] ) - Json + DirectiveToken - (433:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (487:9,62 [9] ) - Component + DirectiveToken - (506:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (550:10,52 [3] ) - Url + DirectiveToken - (563:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (634:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (673:12,14 [104] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (793:13,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (904:14,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [7] MalformedKeyedInject.cshtml) - MyModel + DirectiveToken - (29:1,13 [5] MalformedKeyedInject.cshtml) - MyApp + DirectiveToken - (35:1,19 [14] MalformedKeyedInject.cshtml) - MyPropertyName + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + MalformedDirective - (16:1,0 [34] MalformedKeyedInject.cshtml) - keyedinject + DirectiveToken - (29:1,13 [5] MalformedKeyedInject.cshtml) - MyApp + DirectiveToken - (35:1,19 [14] MalformedKeyedInject.cshtml) - MyPropertyName + HtmlContent - (50:1,34 [9] MalformedKeyedInject.cshtml) + LazyIntermediateToken - (50:1,34 [9] MalformedKeyedInject.cshtml) - Html - "KeyOne\n + Inject - + Inject - + Inject - + Inject - + Inject - + KeyedInject - diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.mappings.txt new file mode 100644 index 00000000000..288e4e4a43f --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_DesignTime.mappings.txt @@ -0,0 +1,15 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml) +|MyModel| +Generated Location: (1239:26,0 [7] ) +|MyModel| + +Source Location: (29:1,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml) +|MyApp| +Generated Location: (1506:36,0 [5] ) +|MyApp| + +Source Location: (35:1,19 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml) +|MyPropertyName| +Generated Location: (1793:46,22 [14] ) +|MyPropertyName| + diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.codegen.cs new file mode 100644 index 00000000000..dc5d96aebee --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.codegen.cs @@ -0,0 +1,79 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "ca787f5e43a2e7d60ca0544b240c00db625c45b9221d3dcf328d1a0874362a24" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MalformedKeyedInject), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml")] +namespace AspNetCoreGeneratedDocument +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"ca787f5e43a2e7d60ca0544b240c00db625c45b9221d3dcf328d1a0874362a24", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml")] + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MalformedKeyedInject : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" +MyModel + +#line default +#line hidden +#nullable disable + > + #nullable disable + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + WriteLiteral("\"KeyOne\r\n"); + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public +#nullable restore +#line (2,14)-(2,19) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" +MyApp + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (2,20)-(2,34) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml" +MyPropertyName + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.diagnostics.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.diagnostics.txt new file mode 100644 index 00000000000..77970f18d15 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.diagnostics.txt @@ -0,0 +1 @@ +TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject.cshtml(2,35): Error RZ1016: The 'keyedinject' directive expects a string surrounded by double quotes. diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.ir.txt new file mode 100644 index 00000000000..3a427254cbc --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MalformedKeyedInject_Runtime.ir.txt @@ -0,0 +1,26 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MalformedKeyedInject - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + MalformedDirective - (16:1,0 [34] MalformedKeyedInject.cshtml) - keyedinject + DirectiveToken - (29:1,13 [5] MalformedKeyedInject.cshtml) - MyApp + DirectiveToken - (35:1,19 [14] MalformedKeyedInject.cshtml) - MyPropertyName + HtmlContent - (50:1,34 [9] MalformedKeyedInject.cshtml) + LazyIntermediateToken - (50:1,34 [9] MalformedKeyedInject.cshtml) - Html - "KeyOne\n + Inject - + Inject - + Inject - + Inject - + Inject - + KeyedInject - diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml new file mode 100644 index 00000000000..1217fba3796 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml @@ -0,0 +1,9 @@ +@model MyModel +@keyedinject MyApp MyPropertyName "KeyOne" +@inject MyApp MyPropertyName +@inject MyService ServiceOne +@keyedinject MyService ServiceOne "KeyOne" +@keyedinject MyService ServiceOne "KeyTwo" +@keyedinject MyApp MyPropertyName2 "SomeKey" +@inject MyApp MyPropertyName2 +@keyedinject MyApp MyPropertyName3 "KeyThree" diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.codegen.cs new file mode 100644 index 00000000000..1b118b32191 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.codegen.cs @@ -0,0 +1,292 @@ +// +#pragma warning disable 1591 +namespace AspNetCoreGeneratedDocument +{ + #line default + using TModel = global::System.Object; + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MixKeyedInject : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage + #nullable disable + { + #pragma warning disable 219 + private void __RazorDirectiveTokenHelpers__() { + ((global::System.Action)(() => { +#nullable restore +#line 1 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyModel __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object MyPropertyName = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 2 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object __typeHelper = "KeyOne"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 3 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object MyPropertyName = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 4 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyService __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 4 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object ServiceOne = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyService __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object ServiceOne = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 5 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object __typeHelper = "KeyOne"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyService __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object ServiceOne = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 6 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object __typeHelper = "KeyTwo"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 7 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 7 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object MyPropertyName2 = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 7 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object __typeHelper = "SomeKey"; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object MyPropertyName2 = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 9 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp __typeHelper = default!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 9 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object MyPropertyName3 = null!; + +#line default +#line hidden +#nullable disable + } + ))(); + ((global::System.Action)(() => { +#nullable restore +#line 9 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +global::System.Object __typeHelper = "KeyThree"; + +#line default +#line hidden +#nullable disable + } + ))(); + } + #pragma warning restore 219 + #pragma warning disable 0414 + private static object __o = null; + #pragma warning restore 0414 + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName2 { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyService ServiceOne { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public MyApp MyPropertyName { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "KeyThree")] + public MyApp MyPropertyName3 { get; private set; } = default!; + #nullable disable + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.codegen.html b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.codegen.html new file mode 100644 index 00000000000..30594788d40 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.codegen.html @@ -0,0 +1,9 @@ +/*~~*/ /*~~~*/ +/*~~~~~~~~*/ /*~*/ /*~~~~~~~~~~*/ /*~~~~*/ +/*~~~*/ /*~*/ /*~~~~~~~~~~*/ +/*~~~*/ /*~~~~~~~~~~~~~*/ /*~~~~~~*/ +/*~~~~~~~~*/ /*~~~~~~~~~~~~~*/ /*~~~~~~*/ /*~~~~*/ +/*~~~~~~~~*/ /*~~~~~~~~~~~~~*/ /*~~~~~~*/ /*~~~~*/ +/*~~~~~~~~*/ /*~*/ /*~~~~~~~~~~~*/ /*~~~~~*/ +/*~~~*/ /*~*/ /*~~~~~~~~~~~*/ +/*~~~~~~~~*/ /*~*/ /*~~~~~~~~~~~*/ /*~~~~~~*/ diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.ir.txt new file mode 100644 index 00000000000..0f8546b29a9 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.ir.txt @@ -0,0 +1,65 @@ +Document - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - - TModel = global::System.Object + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MixKeyedInject - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + DesignTimeDirective - + DirectiveToken - (287:7,8 [62] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper + DirectiveToken - (350:7,71 [4] ) - Html + DirectiveToken - (364:8,8 [54] ) - global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper + DirectiveToken - (419:8,63 [4] ) - Json + DirectiveToken - (433:9,8 [53] ) - global::Microsoft.AspNetCore.Mvc.IViewComponentHelper + DirectiveToken - (487:9,62 [9] ) - Component + DirectiveToken - (506:10,8 [43] ) - global::Microsoft.AspNetCore.Mvc.IUrlHelper + DirectiveToken - (550:10,52 [3] ) - Url + DirectiveToken - (563:11,8 [70] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider + DirectiveToken - (634:11,79 [23] ) - ModelExpressionProvider + DirectiveToken - (673:12,14 [104] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (793:13,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.HeadTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (904:14,14 [95] ) - global::Microsoft.AspNetCore.Mvc.Razor.TagHelpers.BodyTagHelper, Microsoft.AspNetCore.Mvc.Razor + DirectiveToken - (7:0,7 [7] MixKeyedInject.cshtml) - MyModel + DirectiveToken - (29:1,13 [5] MixKeyedInject.cshtml) - MyApp + DirectiveToken - (35:1,19 [14] MixKeyedInject.cshtml) - MyPropertyName + DirectiveToken - (50:1,34 [8] MixKeyedInject.cshtml) - "KeyOne" + DirectiveToken - (68:2,8 [5] MixKeyedInject.cshtml) - MyApp + DirectiveToken - (74:2,14 [14] MixKeyedInject.cshtml) - MyPropertyName + DirectiveToken - (98:3,8 [17] MixKeyedInject.cshtml) - MyService + DirectiveToken - (116:3,26 [10] MixKeyedInject.cshtml) - ServiceOne + DirectiveToken - (141:4,13 [17] MixKeyedInject.cshtml) - MyService + DirectiveToken - (159:4,31 [10] MixKeyedInject.cshtml) - ServiceOne + DirectiveToken - (170:4,42 [8] MixKeyedInject.cshtml) - "KeyOne" + DirectiveToken - (193:5,13 [17] MixKeyedInject.cshtml) - MyService + DirectiveToken - (211:5,31 [10] MixKeyedInject.cshtml) - ServiceOne + DirectiveToken - (222:5,42 [8] MixKeyedInject.cshtml) - "KeyTwo" + DirectiveToken - (245:6,13 [5] MixKeyedInject.cshtml) - MyApp + DirectiveToken - (251:6,19 [15] MixKeyedInject.cshtml) - MyPropertyName2 + DirectiveToken - (267:6,35 [9] MixKeyedInject.cshtml) - "SomeKey" + DirectiveToken - (286:7,8 [5] MixKeyedInject.cshtml) - MyApp + DirectiveToken - (292:7,14 [15] MixKeyedInject.cshtml) - MyPropertyName2 + DirectiveToken - (322:8,13 [5] MixKeyedInject.cshtml) - MyApp + DirectiveToken - (328:8,19 [15] MixKeyedInject.cshtml) - MyPropertyName3 + DirectiveToken - (344:8,35 [10] MixKeyedInject.cshtml) - "KeyThree" + CSharpCode - + IntermediateToken - - CSharp - #pragma warning disable 0414 + CSharpCode - + IntermediateToken - - CSharp - private static object __o = null; + CSharpCode - + IntermediateToken - - CSharp - #pragma warning restore 0414 + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + KeyedInject - diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.mappings.txt new file mode 100644 index 00000000000..99b8b616416 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_DesignTime.mappings.txt @@ -0,0 +1,110 @@ +Source Location: (7:0,7 [7] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyModel| +Generated Location: (1221:26,0 [7] ) +|MyModel| + +Source Location: (29:1,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyApp| +Generated Location: (1482:36,0 [5] ) +|MyApp| + +Source Location: (35:1,19 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyPropertyName| +Generated Location: (1763:46,22 [14] ) +|MyPropertyName| + +Source Location: (50:1,34 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|"KeyOne"| +Generated Location: (2052:56,37 [8] ) +|"KeyOne"| + +Source Location: (68:2,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyApp| +Generated Location: (2290:66,0 [5] ) +|MyApp| + +Source Location: (74:2,14 [14] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyPropertyName| +Generated Location: (2571:76,22 [14] ) +|MyPropertyName| + +Source Location: (98:3,8 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyService| +Generated Location: (2823:86,0 [17] ) +|MyService| + +Source Location: (116:3,26 [10] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|ServiceOne| +Generated Location: (3116:96,22 [10] ) +|ServiceOne| + +Source Location: (141:4,13 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyService| +Generated Location: (3364:106,0 [17] ) +|MyService| + +Source Location: (159:4,31 [10] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|ServiceOne| +Generated Location: (3657:116,22 [10] ) +|ServiceOne| + +Source Location: (170:4,42 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|"KeyOne"| +Generated Location: (3942:126,37 [8] ) +|"KeyOne"| + +Source Location: (193:5,13 [17] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyService| +Generated Location: (4180:136,0 [17] ) +|MyService| + +Source Location: (211:5,31 [10] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|ServiceOne| +Generated Location: (4473:146,22 [10] ) +|ServiceOne| + +Source Location: (222:5,42 [8] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|"KeyTwo"| +Generated Location: (4758:156,37 [8] ) +|"KeyTwo"| + +Source Location: (245:6,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyApp| +Generated Location: (4996:166,0 [5] ) +|MyApp| + +Source Location: (251:6,19 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyPropertyName2| +Generated Location: (5277:176,22 [15] ) +|MyPropertyName2| + +Source Location: (267:6,35 [9] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|"SomeKey"| +Generated Location: (5567:186,37 [9] ) +|"SomeKey"| + +Source Location: (286:7,8 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyApp| +Generated Location: (5806:196,0 [5] ) +|MyApp| + +Source Location: (292:7,14 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyPropertyName2| +Generated Location: (6087:206,22 [15] ) +|MyPropertyName2| + +Source Location: (322:8,13 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyApp| +Generated Location: (6340:216,0 [5] ) +|MyApp| + +Source Location: (328:8,19 [15] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|MyPropertyName3| +Generated Location: (6621:226,22 [15] ) +|MyPropertyName3| + +Source Location: (344:8,35 [10] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml) +|"KeyThree"| +Generated Location: (6911:236,37 [10] ) +|"KeyThree"| + diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_Runtime.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_Runtime.codegen.cs new file mode 100644 index 00000000000..874c0db8455 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_Runtime.codegen.cs @@ -0,0 +1,135 @@ +#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "0c66f7428f024653c40cbe464ecbbc61c0469cca0652db4f6439f5889a52d9e1" +// +#pragma warning disable 1591 +[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(AspNetCoreGeneratedDocument.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MixKeyedInject), @"mvc.1.0.view", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml")] +namespace AspNetCoreGeneratedDocument +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Mvc; + using global::Microsoft.AspNetCore.Mvc.Rendering; + using global::Microsoft.AspNetCore.Mvc.ViewFeatures; + #line default + #line hidden + [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"Sha256", @"0c66f7428f024653c40cbe464ecbbc61c0469cca0652db4f6439f5889a52d9e1", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml")] + [global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemMetadataAttribute("Identifier", "/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml")] + [global::System.Runtime.CompilerServices.CreateNewOnMetadataUpdateAttribute] + #nullable restore + internal sealed class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MixKeyedInject : global::Microsoft.AspNetCore.Mvc.Razor.RazorPage< +#nullable restore +#line (1,8)-(1,15) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyModel + +#line default +#line hidden +#nullable disable + > + #nullable disable + { + #pragma warning disable 1998 + public async override global::System.Threading.Tasks.Task ExecuteAsync() + { + } + #pragma warning restore 1998 + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public +#nullable restore +#line (8,9)-(8,14) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (8,15)-(8,30) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyPropertyName2 + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public +#nullable restore +#line (4,9)-(4,18) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyService + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (4,27)-(4,37) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +ServiceOne + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public +#nullable restore +#line (3,9)-(3,14) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (3,15)-(3,29) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyPropertyName + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.ViewFeatures.IModelExpressionProvider ModelExpressionProvider { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IUrlHelper Url { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.IViewComponentHelper Component { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IJsonHelper Json { get; private set; } = default!; + #nullable disable + #nullable restore + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute] + public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper Html { get; private set; } = default!; + #nullable disable + [global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute(Key = "KeyThree")] + public +#nullable restore +#line (9,14)-(9,19) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyApp + +#line default +#line hidden +#nullable disable + +#nullable restore +#line (9,20)-(9,35) "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject.cshtml" +MyPropertyName3 + +#line default +#line hidden +#nullable disable + { get; private set; } + = default!; + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_Runtime.ir.txt b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_Runtime.ir.txt new file mode 100644 index 00000000000..d30e2d2e469 --- /dev/null +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/MixKeyedInject_Runtime.ir.txt @@ -0,0 +1,24 @@ +Document - + RazorCompiledItemAttribute - + NamespaceDeclaration - - AspNetCoreGeneratedDocument + UsingDirective - (1:0,1 [20] ) - global::System + UsingDirective - (24:1,1 [40] ) - global::System.Collections.Generic + UsingDirective - (67:2,1 [25] ) - global::System.Linq + UsingDirective - (95:3,1 [36] ) - global::System.Threading.Tasks + UsingDirective - (134:4,1 [38] ) - global::Microsoft.AspNetCore.Mvc + UsingDirective - (175:5,1 [48] ) - global::Microsoft.AspNetCore.Mvc.Rendering + UsingDirective - (226:6,1 [51] ) - global::Microsoft.AspNetCore.Mvc.ViewFeatures + RazorSourceChecksumAttribute - + RazorCompiledItemMetadataAttribute - + CreateNewOnMetadataUpdateAttribute - + ClassDeclaration - - internal sealed - TestFiles_IntegrationTests_CodeGenerationIntegrationTest_MixKeyedInject - global::Microsoft.AspNetCore.Mvc.Razor.RazorPage - + MethodDeclaration - - public async override - global::System.Threading.Tasks.Task - ExecuteAsync + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + Inject - + KeyedInject - diff --git a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelperOptionalParam.cshtml b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelperOptionalParam.cshtml index eaef98e676d..7aaa935b851 100644 --- a/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelperOptionalParam.cshtml +++ b/src/Compiler/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/ViewComponentTagHelperOptionalParam.cshtml @@ -10,4 +10,4 @@ - \ No newline at end of file + diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs index 6e493e2172f..acf4b7bf672 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/RazorProjectEngineTest.cs @@ -60,6 +60,7 @@ private static void AssertDefaultFeatures(RazorProjectEngine engine) feature => Assert.IsType(feature), feature => Assert.IsType(feature), feature => Assert.IsType(feature), + feature => Assert.IsType(feature), feature => Assert.IsType(feature), feature => Assert.IsType(feature), feature => Assert.IsType(feature), diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx index 900c52162b9..4b35ed1370b 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/ComponentResources.resx @@ -1,17 +1,17 @@ - @@ -213,6 +213,12 @@ route template + + An optional key for when accessing keyed services. + + + Keyed Services Key + True if whitespace should be preserved, otherwise false. diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentInjectIntermediateNode.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentInjectIntermediateNode.cs index b7076d544ba..3527e2234db 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentInjectIntermediateNode.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentInjectIntermediateNode.cs @@ -26,7 +26,7 @@ public ComponentInjectIntermediateNode(string typeName, string memberName, Sourc TypeSpan = typeSpan; MemberSpan = memberSpan; IsMalformed = isMalformed; - } + } public string TypeName { get; } diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectDirective.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectDirective.cs new file mode 100644 index 00000000000..71a93bff63b --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectDirective.cs @@ -0,0 +1,39 @@ +// 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 Microsoft.AspNetCore.Mvc.Razor.Extensions; + +namespace Microsoft.AspNetCore.Razor.Language.Components; + +// Much of the following is equivalent to Microsoft.AspNetCore.Mvc.Razor.Extensions's InjectDirective, +// but this one outputs properties annotated for Components's property injector, plus it doesn't need to +// support multiple CodeTargets. + +internal static class ComponentKeyedInjectDirective +{ + public static readonly DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( + "keyedinject", + DirectiveKind.SingleLine, + builder => + { + builder.AddTypeToken("TypeName", "The type of the service to inject."); + builder.AddMemberToken("PropertyName", "The name of the property."); + builder.AddStringToken("KeyName", "A key for when accessing keyed services."); + builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; + builder.Description = "Inject a keyed service from the application's service container into a property."; + }); + + public static void Register(RazorProjectEngineBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + builder.AddDirective(Directive, RazorFileKind.Component, RazorFileKind.ComponentImport); + builder.Features.Add(new ComponentKeyedInjectDirectivePass()); + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectDirectivePass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectDirectivePass.cs new file mode 100644 index 00000000000..13b8e8c785a --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectDirectivePass.cs @@ -0,0 +1,91 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using Microsoft.AspNetCore.Mvc.Razor.Extensions; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Razor.Language.Components; + +internal sealed class ComponentKeyedInjectDirectivePass : IntermediateNodePassBase, IRazorDirectiveClassifierPass +{ + protected override void ExecuteCore( + RazorCodeDocument codeDocument, + DocumentIntermediateNode documentNode, + CancellationToken cancellationToken) + { + var visitor = new Visitor(); + visitor.Visit(documentNode); + + // Stop collisions with existing inject directives + var existingMembers = new HashSet(StringComparer.Ordinal); + if (documentNode != null) + { + foreach (var property in documentNode.Children + .OfType()) + { + if (!string.IsNullOrEmpty(property.MemberName)) + { + existingMembers.Add(property.MemberName); + } + } + } + + var properties = new HashSet(StringComparer.Ordinal); + var classNode = documentNode.FindPrimaryClass(); + + for (var i = visitor.Directives.Count - 1; i >= 0; i--) + { + var directive = visitor.Directives[i]; + var tokens = directive.Children.OfType().ToArray(); + var isMalformed = directive is MalformedDirectiveIntermediateNode; + + var hasType = tokens.Length > 0 && !string.IsNullOrWhiteSpace(tokens[0].Content); + Debug.Assert(hasType || isMalformed); + var typeName = hasType ? tokens[0].Content : string.Empty; + var typeSpan = hasType ? tokens[0].Source : directive.Source?.GetZeroWidthEndSpan(); + + var hasMemberName = tokens.Length > 1 && !string.IsNullOrWhiteSpace(tokens[1].Content); + Debug.Assert(hasMemberName || isMalformed); + var memberName = hasMemberName ? tokens[1].Content : null; + var memberSpan = hasMemberName ? tokens[1].Source : null; + + // continue if the membername is in any existing inject statement or in a previous keyedinject statement + if (hasMemberName && (!properties.Add(memberName!) || existingMembers.Contains(memberName!))) + { + continue; + } + var hasKeyName = tokens.Length > 2 && !string.IsNullOrWhiteSpace(tokens[2].Content); + Debug.Assert(hasKeyName || isMalformed); + var keyName = hasKeyName ? tokens[2].Content : null; + var keySpan = hasKeyName ? tokens[2].Source : null; + + classNode!.Children.Add(new ComponentKeyedInjectIntermediateNode(typeName, memberName, typeSpan, memberSpan, isMalformed, keyName, keySpan)); + } + } + + private class Visitor : IntermediateNodeWalker + { + public IList Directives { get; } = []; + + public override void VisitDirective(DirectiveIntermediateNode node) + { + if (node.Directive == ComponentKeyedInjectDirective.Directive) + { + Directives.Add(node); + } + } + + public override void VisitMalformedDirective(MalformedDirectiveIntermediateNode node) + { + if (node.Directive == ComponentKeyedInjectDirective.Directive) + { + Directives.Add(node); + } + } + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectIntermediateNode.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectIntermediateNode.cs new file mode 100644 index 00000000000..d963e1c4a68 --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentKeyedInjectIntermediateNode.cs @@ -0,0 +1,142 @@ +// 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.Collections.Immutable; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; +using Microsoft.AspNetCore.Razor.Language.Intermediate; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace Microsoft.AspNetCore.Razor.Language.Components; + +internal class ComponentKeyedInjectIntermediateNode : ExtensionIntermediateNode +{ + private ImmutableArray injectedPropertyModifiers() { + return [ + $"[global::{ComponentsApi.InjectAttribute.FullTypeName}(Key = {KeyName})]", + "private" // Encapsulation is the default + ]; + } + + public ComponentKeyedInjectIntermediateNode(string typeName, string memberName, SourceSpan? typeSpan, SourceSpan? memberSpan, bool isMalformed, string keyName, SourceSpan? keySpan) + { + TypeName = typeName; + MemberName = memberName; + TypeSpan = typeSpan; + MemberSpan = memberSpan; + IsMalformed = isMalformed; + KeyName = keyName; + KeySource = keySpan; + } + + public string TypeName { get; } + + public string MemberName { get; } + + public SourceSpan? TypeSpan { get; } + + public SourceSpan? MemberSpan { get; } + + public string KeyName { get; set; } + + public SourceSpan? KeySource { get; set; } + + public bool IsMalformed { get; } + + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; + + public override void Accept(IntermediateNodeVisitor visitor) + { + if (visitor == null) + { + throw new ArgumentNullException(nameof(visitor)); + } + + AcceptExtensionNode(this, visitor); + } + + public override void WriteNode(CodeTarget target, CodeRenderingContext context) + { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (TypeName == string.Empty && TypeSpan.HasValue && !context.Options.DesignTime) + { + // if we don't even have a type name, just emit an empty mapped region so that intellisense still works + using (context.BuildEnhancedLinePragma(TypeSpan.Value)) + { + } + } + else + { + + var memberName = MemberName ?? "Member_" + DefaultTagHelperTargetExtension.GetDeterministicId(context); + + if (!context.Options.DesignTime || !IsMalformed) + { + // I was just writing out the key with string interpolation here with no source mappings but that was messing with the + // integration tests. Leaving it like this but not sure what is preferred. + context.CodeWriter.Write($"[global::{ComponentsApi.InjectAttribute.FullTypeName}("); + + context.CodeWriter.Write("Key = "); + + using (context.BuildEnhancedLinePragma(KeySource)) + { + context.CodeWriter.Write(KeyName); + } + + context.CodeWriter.Write(")]"); + + // + WriteToken(context.CodeWriter, TypeName, TypeSpan, context); + context.CodeWriter.Write(" "); + WriteToken(context.CodeWriter, memberName, MemberSpan, context); + + static void WriteToken(CodeWriter writer, string content, SourceSpan? span, CodeRenderingContext context) + { + if (span is not null && context?.Options.DesignTime == false) + { + using (context.BuildEnhancedLinePragma(span)) + { + writer.Write(content); + } + } + else + { + writer.Write(content); + } + } + + context.CodeWriter.Write(" { get;"); + + context.CodeWriter.WriteLine(" set; }"); + + if (context?.Options is { SuppressNullabilityEnforcement: false, DesignTime: false }) + { + context.CodeWriter.WriteLine(" = default!;"); + } + + + + //context.CodeWriter.WriteAutoPropertyDeclaration( + // injectedPropertyModifiers(), + // TypeName, + // memberName, + // TypeSpan, + // MemberSpan, + // context, + // defaultValue: true); + } + } + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/CSharpCodeParser.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/CSharpCodeParser.cs index 9e9b47b7d43..d3ac5dd7461 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/CSharpCodeParser.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Legacy/CSharpCodeParser.cs @@ -1677,6 +1677,8 @@ private void ParseExtensibleDirective(in SyntaxListBuilder buil break; case DirectiveTokenKind.String: + // Either make this a move on if the currenttoken is a semicolon and it is optional or change order. + // Changing order probably simpler if (At(SyntaxKind.StringLiteral) && !CurrentToken.ContainsDiagnostics) { AcceptAndMoveNext(); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs index 3427898e1a1..c50d59ef7a4 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/RazorProjectEngine.cs @@ -403,6 +403,7 @@ private static void AddComponentFeatures(RazorProjectEngineBuilder builder, Razo // Directives (conditional on file kind) ComponentCodeDirective.Register(builder); ComponentInjectDirective.Register(builder); + ComponentKeyedInjectDirective.Register(builder); ComponentLayoutDirective.Register(builder); ComponentPageDirective.Register(builder); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/IKeyedInjectTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/IKeyedInjectTargetExtension.cs new file mode 100644 index 00000000000..fd2a6e4f7f1 --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/IKeyedInjectTargetExtension.cs @@ -0,0 +1,13 @@ +// 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 Microsoft.AspNetCore.Razor.Language.CodeGeneration; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; + +public interface IKeyedInjectTargetExtension : ICodeTargetExtension +{ + void WriteKeyedInjectProperty(CodeRenderingContext context, KeyedInjectIntermediateNode node); +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectDirective.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectDirective.cs new file mode 100644 index 00000000000..f3d49a5797a --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectDirective.cs @@ -0,0 +1,171 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading; +using Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; + +public static class KeyedInjectDirective +{ + public static readonly DirectiveDescriptor Directive = DirectiveDescriptor.CreateDirective( + "keyedinject", + DirectiveKind.SingleLine, + builder => + { + builder + .AddTypeToken(RazorExtensionsResources.KeyedInjectDirective_TypeToken_Name, RazorExtensionsResources.KeyedInjectDirective_TypeToken_Description) + .AddMemberToken(RazorExtensionsResources.KeyedInjectDirective_MemberToken_Name, RazorExtensionsResources.KeyedInjectDirective_MemberToken_Description) + .AddStringToken(RazorExtensionsResources.KeyedInjectDirective_KeyToken_Name, RazorExtensionsResources.KeyedInjectDirective_KeyToken_Description); + + builder.Usage = DirectiveUsage.FileScopedMultipleOccurring; + builder.Description = RazorExtensionsResources.KeyedInjectDirective_Description; + }); + + public static RazorProjectEngineBuilder Register(RazorProjectEngineBuilder builder, bool considerNullabilityEnforcement) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + builder.AddDirective(Directive); + builder.Features.Add(new Pass()); + builder.AddTargetExtension(new KeyedInjectTargetExtension(considerNullabilityEnforcement)); + return builder; + } + + internal sealed class Pass : IntermediateNodePassBase, IRazorDirectiveClassifierPass + { + // Runs after the @model and @namespace directives + public override int Order => 10; + + protected override void ExecuteCore( + RazorCodeDocument codeDocument, + DocumentIntermediateNode documentNode, + CancellationToken cancellationToken) + { + if (documentNode.DocumentKind != RazorPageDocumentClassifierPass.RazorPageDocumentKind && + documentNode.DocumentKind != MvcViewDocumentClassifierPass.MvcViewDocumentKind) + { + // Not a MVC file. Skip. + return; + } + + var visitor = new Visitor(); + visitor.Visit(documentNode); + var modelType = ModelDirective.GetModelType(documentNode).Content; + + // Stop collisions with existing inject directives + var existingMembers = new HashSet(StringComparer.Ordinal); + if (visitor.Class != null) + { + foreach (var property in visitor.Class.Children + .OfType()) + { + if (!string.IsNullOrEmpty(property.MemberName)) + { + existingMembers.Add(property.MemberName); + } + } + } + + var properties = new HashSet(StringComparer.Ordinal); + + for (var i = visitor.Directives.Count - 1; i >= 0; i--) + { + var directive = visitor.Directives[i]; + var tokens = directive.Children.OfType().ToArray(); + var isMalformed = directive is MalformedDirectiveIntermediateNode; + + var hasType = tokens.Length > 0 && !string.IsNullOrWhiteSpace(tokens[0].Content); + Debug.Assert(hasType || isMalformed); + var typeName = hasType ? tokens[0].Content : string.Empty; + var typeSpan = hasType ? tokens[0].Source : directive.Source?.GetZeroWidthEndSpan(); + + var hasMemberName = tokens.Length > 1 && !string.IsNullOrWhiteSpace(tokens[1].Content); + Debug.Assert(hasMemberName || isMalformed); + var memberName = hasMemberName ? tokens[1].Content : null; + var memberSpan = hasMemberName ? tokens[1].Source : null; + // continue if the membername is in any existing inject statement or in a previous keyedinject statement + if (hasMemberName && (!properties.Add(memberName!) || existingMembers.Contains(memberName!))) + { + continue; + } + + var hasKeyName = tokens.Length > 2 && !string.IsNullOrWhiteSpace(tokens[2].Content); + Debug.Assert(hasKeyName || isMalformed); + var keyName = hasKeyName ? ValidateStringToken(tokens[2].Content) : null; + var keySpan = hasKeyName ? tokens[2].Source : null; + + const string tModel = ""; + if (typeName.EndsWith(tModel, StringComparison.Ordinal)) + { + typeName = typeName[..^tModel.Length] + "<" + modelType + ">"; + if (typeSpan.HasValue) + { + typeSpan = new SourceSpan(typeSpan.Value.FilePath, typeSpan.Value.AbsoluteIndex, typeSpan.Value.LineIndex, typeSpan.Value.CharacterIndex, typeSpan.Value.Length - tModel.Length, typeSpan.Value.LineCount, typeSpan.Value.EndCharacterIndex - tModel.Length); + } + } + + var injectNode = new KeyedInjectIntermediateNode() + { + TypeName = typeName, + MemberName = memberName, + TypeSource = typeSpan, + MemberSource = memberSpan, + KeyName = keyName, + KeySource = keySpan, + IsMalformed = isMalformed + }; + + visitor.Class!.Children.Add(injectNode); + } + } + + private static string ValidateStringToken(string token) + { + // Tokens aren't captured if they're malformed. Therefore, this method will + // always be called with a valid token content. + Debug.Assert(token.StartsWith("\"", StringComparison.Ordinal)); + Debug.Assert(token.EndsWith("\"", StringComparison.Ordinal)); + + return token; + } + } + + private class Visitor : IntermediateNodeWalker + { + public ClassDeclarationIntermediateNode? Class { get; private set; } + + public IList Directives { get; } = []; + + public override void VisitClassDeclaration(ClassDeclarationIntermediateNode node) + { + Class ??= node; + + base.VisitClassDeclaration(node); + } + + public override void VisitDirective(DirectiveIntermediateNode node) + { + if (node.Directive == Directive) + { + Directives.Add(node); + } + } + + public override void VisitMalformedDirective(MalformedDirectiveIntermediateNode node) + { + if (node.Directive == Directive) + { + Directives.Add(node); + } + } + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectIntermediateNode.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectIntermediateNode.cs new file mode 100644 index 00000000000..e598ed5ac41 --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectIntermediateNode.cs @@ -0,0 +1,73 @@ +// 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 Microsoft.AspNetCore.Razor.Language; +using Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Intermediate; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; + +public class KeyedInjectIntermediateNode : ExtensionIntermediateNode +{ + public string TypeName { get; set; } + + public SourceSpan? TypeSource { get; set; } + + public string MemberName { get; set; } + + public SourceSpan? MemberSource { get; set; } + + public bool IsMalformed { get; set; } + + public string KeyName { get; set; } + + public SourceSpan? KeySource { get; set; } + + public override IntermediateNodeCollection Children => IntermediateNodeCollection.ReadOnly; + + public override void Accept(IntermediateNodeVisitor visitor) + { + if (visitor == null) + { + + throw new ArgumentNullException(nameof(visitor)); + } + + AcceptExtensionNode(this, visitor); + } + + public override void WriteNode(CodeTarget target, CodeRenderingContext context) + { + if (target == null) + { + throw new ArgumentNullException(nameof(target)); + } + + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + var extension = target.GetExtension(); + if (extension == null) + { + ReportMissingCodeTargetExtension(context); + return; + } + + extension.WriteKeyedInjectProperty(context, this); + } + + public override void FormatNode(IntermediateNodeFormatter formatter) + { + formatter.WriteContent(MemberName); + + formatter.WriteProperty(nameof(MemberName), MemberName); + formatter.WriteProperty(nameof(TypeName), TypeName); + formatter.WriteProperty(nameof(KeyName), KeyName); + formatter.WriteProperty(nameof(IsMalformed), IsMalformed.ToString()); + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectTargetExtension.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectTargetExtension.cs new file mode 100644 index 00000000000..09bdd7eaae6 --- /dev/null +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/KeyedInjectTargetExtension.cs @@ -0,0 +1,93 @@ +// 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 Microsoft.AspNetCore.Razor.Language.CodeGeneration; +using Microsoft.AspNetCore.Razor.Language.Extensions; +using static Microsoft.AspNetCore.Razor.Language.Components.ComponentNodeWriter; + +namespace Microsoft.AspNetCore.Mvc.Razor.Extensions; + +public class KeyedInjectTargetExtension(bool considerNullabilityEnforcement) : IKeyedInjectTargetExtension +{ + private const string RazorInjectAttribute = "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute]"; + private const string RazorInjectAttributeWithAsterix = "[global::Microsoft.AspNetCore.Mvc.Razor.Internal.RazorInjectAttribute*]"; + + private string GetRazorInjectAttributeWithKey(string key) { + + // If there is a key write it into inject attribute + return string.IsNullOrEmpty(key) ? RazorInjectAttribute : RazorInjectAttributeWithAsterix.Replace("*", $"(Key = {key})"); + } + + public void WriteKeyedInjectProperty(CodeRenderingContext context, KeyedInjectIntermediateNode node) + { + if (context == null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (node == null) + { + throw new ArgumentNullException(nameof(node)); + } + + if (!context.Options.DesignTime && !string.IsNullOrWhiteSpace(node.TypeSource?.FilePath)) + { + if (node.TypeName == "") + { + // if we don't even have a type name, just emit an empty mapped region so that intellisense still works + using (context.BuildEnhancedLinePragma(node.TypeSource.Value)) + { + } + } + else + { + var keyName = node.KeyName; + + context.CodeWriter.WriteLine(GetRazorInjectAttributeWithKey(keyName)); + + var memberName = node.MemberName ?? "Member_" + DefaultTagHelperTargetExtension.GetDeterministicId(context); + context.CodeWriter.WriteAutoPropertyDeclaration(["public"], node.TypeName, memberName, node.TypeSource, node.MemberSource, context, privateSetter: true, defaultValue: true); + } + } + else if (!node.IsMalformed) + { + var property = $"public {node.TypeName} {node.MemberName} {{ get; private set; }}"; + if (considerNullabilityEnforcement && !context.Options.SuppressNullabilityEnforcement) + { + property += " = default!;"; + } + + if (node.Source.HasValue) + { + using (context.BuildLinePragma(node.Source.Value)) + { + WriteProperty(); + } + } + else + { + WriteProperty(); + } + + void WriteProperty() + { + if (considerNullabilityEnforcement && !context.Options.SuppressNullabilityEnforcement) + { + context.CodeWriter.WriteLine("#nullable restore"); + } + + context.CodeWriter + .WriteLine(GetRazorInjectAttributeWithKey(node.KeyName)) + .WriteLine(property); + + if (considerNullabilityEnforcement && !context.Options.SuppressNullabilityEnforcement) + { + context.CodeWriter.WriteLine("#nullable disable"); + } + } + } + } +} diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensions.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensions.cs index 027d6998f99..a55f82fd622 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensions.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensions.cs @@ -16,6 +16,7 @@ public static void Register(RazorProjectEngineBuilder builder) ArgHelper.ThrowIfNull(builder); InjectDirective.Register(builder, considerNullabilityEnforcement: true); + KeyedInjectDirective.Register(builder, considerNullabilityEnforcement: true); ModelDirective.Register(builder); PageDirective.Register(builder); diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensionsResources.resx b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensionsResources.resx index e7e13dd292c..475427ae511 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensionsResources.resx +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Mvc/RazorExtensionsResources.resx @@ -1,17 +1,17 @@ - + - @@ -120,6 +120,27 @@ Value cannot be null or empty. + + Inject a keyed service from the application's service container into a property. + + + The name of the property. + + + PropertyName + + + The type of the service to inject. + + + TypeName + + + A key for when accessing keyed services. + + + Keyed Services Key + Inject a service from the application's service container into a property. @@ -135,6 +156,12 @@ TypeName + Specify the view or page model for the page. @@ -189,4 +216,4 @@ Method '{0}' of view component '{1}' should be declared to return a value. - \ No newline at end of file + diff --git a/src/Shared/files/LanguageSupport/IsExternalInit.cs b/src/Shared/files/LanguageSupport/IsExternalInit.cs index e7d2d5e6590..337a5abaef7 100644 --- a/src/Shared/files/LanguageSupport/IsExternalInit.cs +++ b/src/Shared/files/LanguageSupport/IsExternalInit.cs @@ -6,7 +6,6 @@ using System.ComponentModel; namespace System.Runtime.CompilerServices; - /// /// Reserved to be used by the compiler for tracking metadata. /// This class should not be used by developers in source code.