private static IList BuildParameters()

in Libraries/src/Amazon.Lambda.Annotations.SourceGenerator/Models/GeneratedMethodModelBuilder.cs [146:237]


        private static IList<ParameterModel> BuildParameters(IMethodSymbol lambdaMethodSymbol,
            LambdaMethodModel lambdaMethodModel, GeneratorExecutionContext context)
        {
            var parameters = new List<ParameterModel>();

            var contextParameter = new ParameterModel
            {
                Name = "__context__",
                Type = new TypeModel
                {
                    FullName = TypeFullNames.ILambdaContext
                },
                Documentation = "The ILambdaContext that provides methods for logging and describing the Lambda environment."
            };

            if (lambdaMethodSymbol.HasAttribute(context, TypeFullNames.RestApiAttribute))
            {
                var symbol = context.Compilation.GetTypeByMetadataName(TypeFullNames.APIGatewayProxyRequest);
                var type = TypeModelBuilder.Build(symbol, context);
                var requestParameter = new ParameterModel
                {
                    Name = "__request__",
                    Type = type,
                    Documentation = "The API Gateway request object that will be processed by the Lambda function handler."
                };
                parameters.Add(requestParameter);
                parameters.Add(contextParameter);
            }
            else if (lambdaMethodSymbol.HasAttribute(context, TypeFullNames.HttpApiAttribute))
            {
                var version = GetHttpApiVersion(lambdaMethodSymbol, context);
                TypeModel type;
                switch (version)
                {
                    case HttpApiVersion.V1:
                    {
                        var symbol = context.Compilation.GetTypeByMetadataName(TypeFullNames.APIGatewayProxyRequest);
                        type = TypeModelBuilder.Build(symbol, context);
                        break;
                    }
                    case HttpApiVersion.V2:
                    {
                        var symbol = context.Compilation.GetTypeByMetadataName(TypeFullNames.APIGatewayHttpApiV2ProxyRequest);
                        type = TypeModelBuilder.Build(symbol, context);
                        break;
                    }
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                var requestParameter = new ParameterModel
                {
                    Name = "__request__",
                    Type = type,
                    Documentation = "The API Gateway request object that will be processed by the Lambda function handler."
                };
                parameters.Add(requestParameter);
                parameters.Add(contextParameter);
            }
            else
            {
                // Lambda method with no event attribute are plain lambda functions, therefore, generated method will have
                // same parameter as original method except DI injected parameters
                foreach (var param in lambdaMethodModel.Parameters)
                {
                    if (param.Attributes.Any(att => att.Type.FullName == TypeFullNames.FromServiceAttribute))
                    {
                        continue;
                    }
                    // If the Lambda function is taking in the ILambdaContext object make sure in the generated wrapper code we
                    // use the same system name for the ILambdaContext variable as all of the other places use.
                    else if(param.Type.FullName == TypeFullNames.ILambdaContext)
                    {
                        param.Name = "__context__";
                        param.Documentation = "The ILambdaContext that provides methods for logging and describing the Lambda environment.";
                    }
                    else
                    {
                        // Somehow, Roslyn doesn't include @ character when using with reserved keyword. Add a check just in case Roslyn fix is implemented in later versions.
                        if (!param.Name.StartsWith("@"))
                        {
                            param.Name = "__" + param.Name + "__";
                        }
                        param.Documentation = "The request object that will be processed by the Lambda function handler.";
                    }

                    parameters.Add(param);
                }
            }

            return parameters;
        }