本文整理汇总了C#中SyntaxGenerator.WithTypeArguments方法的典型用法代码示例。如果您正苦于以下问题:C# SyntaxGenerator.WithTypeArguments方法的具体用法?C# SyntaxGenerator.WithTypeArguments怎么用?C# SyntaxGenerator.WithTypeArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SyntaxGenerator
的用法示例。
在下文中一共展示了SyntaxGenerator.WithTypeArguments方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMethodStatementsSyntax
private static IEnumerable<SyntaxNode> GetMethodStatementsSyntax(
SyntaxGenerator syntaxGenerator,
SemanticModel semanticModel,
IMethodSymbol methodSymbol)
{
// GENERATED CODE (for every ref or out parameter):
//
// string someOutParameter;
// var someRefParameter = default(int);
for (var i = 0; i < methodSymbol.Parameters.Length; ++i)
{
var parameter = methodSymbol.Parameters[i];
if (parameter.RefKind == RefKind.Out)
{
yield return syntaxGenerator
.LocalDeclarationStatement(
syntaxGenerator.TypeExpression(parameter.Type),
GetNameForParameter(methodSymbol, parameter));
}
else if (parameter.RefKind == RefKind.Ref)
{
yield return syntaxGenerator
.LocalDeclarationStatement(
GetNameForParameter(methodSymbol, parameter),
initializer: syntaxGenerator.DefaultExpression(syntaxGenerator.TypeExpression(parameter.Type)));
}
}
var arguments = methodSymbol
.Parameters
.Select(x =>
syntaxGenerator
.Argument(
x.RefKind,
syntaxGenerator.IdentifierName(GetNameForParameter(methodSymbol, x))))
.ToList();
var typeArguments = methodSymbol
.TypeArguments
.Select(x => syntaxGenerator.TypeExpression(x))
.ToList();
var lambdaParameterName = GetUniqueName(methodSymbol);
var lambdaInvocation = syntaxGenerator
.MemberAccessExpression(
syntaxGenerator.IdentifierName(lambdaParameterName),
methodSymbol.Name);
if (typeArguments.Count > 0)
{
lambdaInvocation = syntaxGenerator
.WithTypeArguments(
lambdaInvocation,
typeArguments);
}
// GENERATED CODE (for every ref or out parameter):
//
// someOutParameter = this.GetOutParameterValue<string>(x => x.TheMethod(out someOutParameter), parameterIndex: 0);
// someRefParameter = this.GetRefParameterValue<int>(x => x.TheMethod(ref someRefParameter), parameterIndex: 0);
for (var i = 0; i < methodSymbol.Parameters.Length; ++i)
{
var parameter = methodSymbol.Parameters[i];
if (parameter.RefKind == RefKind.Out || parameter.RefKind == RefKind.Ref)
{
var nameOfMethodToCall = parameter.RefKind == RefKind.Out ? "GetOutParameterValue" : "GetRefParameterValue";
yield return syntaxGenerator
.AssignmentStatement(
syntaxGenerator.IdentifierName(parameter.Name),
syntaxGenerator
.InvocationExpression(
syntaxGenerator.MemberAccessExpression(
syntaxGenerator.ThisExpression(),
syntaxGenerator.GenericName(
nameOfMethodToCall,
typeArguments: syntaxGenerator.TypeExpression(parameter.Type))),
arguments: new[]
{
syntaxGenerator.ValueReturningLambdaExpression(
lambdaParameterName,
syntaxGenerator.InvocationExpression(
lambdaInvocation,
arguments: arguments)),
syntaxGenerator.LiteralExpression(i)
}));
}
}
// GENERATED CODE:
//
// [return] this.Apply(x => x.SomeMethod(param1, param2));
var applyInvocation = syntaxGenerator
.InvocationExpression(
syntaxGenerator.MemberAccessExpression(
syntaxGenerator.ThisExpression(),
"Apply"),
//.........这里部分代码省略.........