private static LocalFunctionStatementSyntax GetNewNode(
            LocalFunctionStatementSyntax localFunctionStatement,
            TypeParameterConstraintSyntax constraint,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            string name = GetMethodTypeParameterName(semanticModel, localFunctionStatement.BodyOrExpressionBody().SpanStart, cancellationToken);

            LocalFunctionStatementSyntax newNode = localFunctionStatement.AddTypeParameterListParameters(TypeParameter(Identifier(name).WithRenameAnnotation()));

            if (constraint != null)
            {
                newNode = newNode.AddConstraintClauses(TypeParameterConstraintClause(name, constraint));
            }

            return(newNode);
        }
Exemplo n.º 2
0
        public static ParametersInfo Create(LocalFunctionStatementSyntax localFunction, bool allowMissing = false)
        {
            ParameterListSyntax parameterList = localFunction.ParameterList;

            if (!Check(parameterList, allowMissing))
            {
                return(Default);
            }

            SeparatedSyntaxList <ParameterSyntax> parameters = parameterList.Parameters;

            if (!CheckParameters(parameters, allowMissing))
            {
                return(Default);
            }

            TypeParameterListSyntax typeParameterList = localFunction.TypeParameterList;
            SeparatedSyntaxList <TypeParameterSyntax> typeParameters = typeParameterList?.Parameters ?? default(SeparatedSyntaxList <TypeParameterSyntax>);

            if (!CheckTypeParameters(typeParameters, allowMissing))
            {
                return(Default);
            }

            if (!parameters.Any() &&
                !typeParameters.Any())
            {
                return(Default);
            }

            CSharpSyntaxNode body = localFunction.BodyOrExpressionBody();

            if (!Check(body, allowMissing))
            {
                return(Default);
            }

            return(new ParametersInfo(typeParameterList, parameterList, body));
        }
Exemplo n.º 3
0
 protected override CSharpSyntaxNode GetBody(LocalFunctionStatementSyntax node)
 {
     return(node.BodyOrExpressionBody());
 }