Add support for method parameters to Razor IR
This commit is contained in:
parent
fcf6ea03a9
commit
59a1cf9293
|
|
@ -159,11 +159,35 @@ namespace Microsoft.AspNetCore.Razor.Language.CodeGeneration
|
||||||
Context.CodeWriter.Write(" ");
|
Context.CodeWriter.Write(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
Context.CodeWriter
|
Context.CodeWriter.Write(node.ReturnType);
|
||||||
.Write(node.ReturnType)
|
Context.CodeWriter.Write(" ");
|
||||||
.Write(" ")
|
|
||||||
.Write(node.MethodName)
|
Context.CodeWriter.Write(node.MethodName);
|
||||||
.WriteLine("()");
|
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())
|
using (Context.CodeWriter.BuildScope())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ namespace Microsoft.AspNetCore.Razor.Language.Intermediate
|
||||||
|
|
||||||
public string MethodName { get; set; }
|
public string MethodName { get; set; }
|
||||||
|
|
||||||
|
public IList<MethodParameter> Parameters { get; } = new List<MethodParameter>();
|
||||||
|
|
||||||
public string ReturnType { get; set; }
|
public string ReturnType { get; set; }
|
||||||
|
|
||||||
public override void Accept(IntermediateNodeVisitor visitor)
|
public override void Accept(IntermediateNodeVisitor visitor)
|
||||||
|
|
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -260,6 +260,24 @@ internal class TestClass : TestBase, IFoo, IBar
|
||||||
"async",
|
"async",
|
||||||
},
|
},
|
||||||
MethodName = "TestMethod",
|
MethodName = "TestMethod",
|
||||||
|
Parameters =
|
||||||
|
{
|
||||||
|
new MethodParameter()
|
||||||
|
{
|
||||||
|
Modifiers =
|
||||||
|
{
|
||||||
|
"readonly",
|
||||||
|
"ref",
|
||||||
|
},
|
||||||
|
ParameterName = "a",
|
||||||
|
TypeName = "int",
|
||||||
|
},
|
||||||
|
new MethodParameter()
|
||||||
|
{
|
||||||
|
ParameterName = "b",
|
||||||
|
TypeName = "string",
|
||||||
|
}
|
||||||
|
},
|
||||||
ReturnType = "string",
|
ReturnType = "string",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -279,7 +297,7 @@ internal class TestClass : TestBase, IFoo, IBar
|
||||||
// <auto-generated/>
|
// <auto-generated/>
|
||||||
#pragma warning disable 1591
|
#pragma warning disable 1591
|
||||||
#pragma warning disable 1998
|
#pragma warning disable 1998
|
||||||
internal virtual async string TestMethod()
|
internal virtual async string TestMethod(readonly ref int a, string b)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#pragma warning restore 1998
|
#pragma warning restore 1998
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue