Add support for method parameters to Razor IR

This commit is contained in:
Ryan Nowak 2018-02-19 14:38:03 -08:00
parent fcf6ea03a9
commit 59a1cf9293
4 changed files with 66 additions and 6 deletions

View File

@ -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())
{

View File

@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
public string MethodName { get; set; }
public IList<MethodParameter> Parameters { get; } = new List<MethodParameter>();
public string ReturnType { get; set; }
public override void Accept(IntermediateNodeVisitor visitor)

View File

@ -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<string> Modifiers { get; } = new List<string>();
public string TypeName { get; set; }
public string ParameterName { get; set; }
}
}

View File

@ -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
// <auto-generated/>
#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