diff --git a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs index 772c5a0fab..09ed47b6fa 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/CodeGeneration/DefaultDocumentWriter.cs @@ -159,11 +159,35 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration Context.CodeWriter.Write(" "); } - Context.CodeWriter - .Write(node.ReturnType) - .Write(" ") - .Write(node.MethodName) - .WriteLine("()"); + Context.CodeWriter.Write(node.ReturnType); + Context.CodeWriter.Write(" "); + + Context.CodeWriter.Write(node.MethodName); + Context.CodeWriter.Write("("); + + for (var i = 0; i < node.Parameters.Count; i++) + { + var parameter = node.Parameters[i]; + + for (var j = 0; j < parameter.Modifiers.Count; j++) + { + Context.CodeWriter.Write(parameter.Modifiers[j]); + Context.CodeWriter.Write(" "); + } + + Context.CodeWriter.Write(parameter.TypeName); + Context.CodeWriter.Write(" "); + + Context.CodeWriter.Write(parameter.ParameterName); + + if (i < node.Parameters.Count - 1) + { + Context.CodeWriter.Write(", "); + } + } + + Context.CodeWriter.Write(")"); + Context.CodeWriter.WriteLine(); using (Context.CodeWriter.BuildScope()) { diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs index 85bdd7641e..e1a039c5e0 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodDeclarationIntermediateNode.cs @@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate public string MethodName { get; set; } + public IList Parameters { get; } = new List(); + public string ReturnType { get; set; } public override void Accept(IntermediateNodeVisitor visitor) diff --git a/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodParameter.cs b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodParameter.cs new file mode 100644 index 0000000000..6838f73d7d --- /dev/null +++ b/src/Microsoft.AspNetCore.Razor.Language/Intermediate/MethodParameter.cs @@ -0,0 +1,16 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Collections.Generic; + +namespace Microsoft.AspNetCore.Razor.Language.Intermediate +{ + public sealed class MethodParameter + { + public IList Modifiers { get; } = new List(); + + public string TypeName { get; set; } + + public string ParameterName { get; set; } + } +} diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DefaultDocumentWriterTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DefaultDocumentWriterTest.cs index 99678f74b6..67b03f39b8 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DefaultDocumentWriterTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/CodeGeneration/DefaultDocumentWriterTest.cs @@ -260,6 +260,24 @@ internal class TestClass : TestBase, IFoo, IBar "async", }, MethodName = "TestMethod", + Parameters = + { + new MethodParameter() + { + Modifiers = + { + "readonly", + "ref", + }, + ParameterName = "a", + TypeName = "int", + }, + new MethodParameter() + { + ParameterName = "b", + TypeName = "string", + } + }, ReturnType = "string", }); @@ -279,7 +297,7 @@ internal class TestClass : TestBase, IFoo, IBar // #pragma warning disable 1591 #pragma warning disable 1998 -internal virtual async string TestMethod() +internal virtual async string TestMethod(readonly ref int a, string b) { } #pragma warning restore 1998