private void GenerateMethod(TypeEmitter typeEmitter, List <EmittedProperty> emittedProperties, MethodModel method)
        {
            var methodEmitter        = typeEmitter.EmitMethod(method);
            var serializationMethods = new ResolvedSerializationMethods(this.typeModel.SerializationMethodsAttribute?.Attribute, method.SerializationMethodsAttribute?.Attribute);

            if (method.RequestAttribute == null)
            {
                this.diagnostics.ReportMethodMustHaveRequestAttribute(method);
            }
            else
            {
                string?path = method.RequestAttribute.Attribute.Path;
                this.ValidatePathParams(method, path);
                this.ValidateCancellationTokenParams(method);
                this.ValidateMultipleBodyParams(method);
                this.ValidateHttpRequestMessageParams(method);

                methodEmitter.EmitRequestInfoCreation(method.RequestAttribute.Attribute);

                var resolvedAllowAnyStatusCode = method.AllowAnyStatusCodeAttribute ?? this.typeModel.TypeAllowAnyStatusCodeAttribute;
                if (resolvedAllowAnyStatusCode?.Attribute.AllowAnyStatusCode == true)
                {
                    methodEmitter.EmitSetAllowAnyStatusCode();
                }

                if (this.typeModel.BasePathAttribute?.Attribute.BasePath != null)
                {
                    methodEmitter.EmitSetBasePath(this.typeModel.BasePathAttribute.Attribute.BasePath);
                }

                this.GenerateMethodProperties(methodEmitter, emittedProperties, serializationMethods);

                foreach (var methodHeader in method.HeaderAttributes)
                {
                    if (methodHeader.Attribute.Name.Contains(":"))
                    {
                        this.diagnostics.ReportHeaderOnMethodMustNotHaveColonInName(method, methodHeader);
                    }

                    methodEmitter.EmitAddMethodHeader(methodHeader);
                }

                this.GenerateMethodParameters(methodEmitter, method, serializationMethods);

                if (!methodEmitter.TryEmitRequestMethodInvocation())
                {
                    this.diagnostics.ReportMethodMustHaveValidReturnType(method);
                }
            }
        }
        private void GenerateMethodParameters(MethodEmitter methodEmitter, MethodModel method, ResolvedSerializationMethods serializationMethods)
        {
            foreach (var parameter in method.Parameters)
            {
                var attributes = parameter.GetAllSetAttributes().ToList();

                if (parameter.IsByRef)
                {
                    this.diagnostics.ReportParameterMustNotBeByRef(method, parameter);
                }

                if (parameter.IsCancellationToken)
                {
                    if (attributes.Count > 0)
                    {
                        this.diagnostics.ReportCancellationTokenMustHaveZeroAttributes(method, parameter);
                    }

                    methodEmitter.EmitSetCancellationToken(parameter);
                }
                else
                {
                    if (attributes.Count > 1)
                    {
                        this.diagnostics.ReportParameterMustHaveZeroOrOneAttributes(method, parameter, attributes);
                    }

                    if (parameter.HeaderAttribute != null)
                    {
                        if (parameter.HeaderAttribute.Attribute.Value != null)
                        {
                            this.diagnostics.ReportHeaderParameterMustNotHaveValue(method, parameter);
                        }
                        if (parameter.HeaderAttribute.Attribute.Name.Contains(":"))
                        {
                            this.diagnostics.ReportHeaderParameterMustNotHaveColonInName(method, parameter);
                        }

                        methodEmitter.EmitAddHeaderParameter(parameter);
                    }
                    else if (parameter.PathAttribute != null)
                    {
                        methodEmitter.EmitAddPathParameter(
                            parameter,
                            serializationMethods.ResolvePath(parameter.PathAttribute.Attribute.SerializationMethod));
                    }
                    else if (parameter.QueryAttribute != null)
                    {
                        methodEmitter.EmitAddQueryParameter(
                            parameter,
                            serializationMethods.ResolveQuery(parameter.QueryAttribute.Attribute.SerializationMethod));
                    }
                    else if (parameter.HttpRequestMessagePropertyAttribute != null)
                    {
                        methodEmitter.EmitAddHttpRequestMessagePropertyParameter(parameter);
                    }
                    else if (parameter.RawQueryStringAttribute != null)
                    {
                        methodEmitter.EmitAddRawQueryStringParameter(parameter);
                    }
                    else if (parameter.QueryMapAttribute != null)
                    {
                        if (!methodEmitter.TryEmitAddQueryMapParameter(parameter, serializationMethods.ResolveQuery(parameter.QueryMapAttribute.Attribute.SerializationMethod)))
                        {
                            this.diagnostics.ReportQueryMapParameterIsNotADictionary(method, parameter);
                        }
                    }
                    else if (parameter.BodyAttribute != null)
                    {
                        methodEmitter.EmitSetBodyParameter(
                            parameter,
                            serializationMethods.ResolveBody(parameter.BodyAttribute.Attribute.SerializationMethod));
                    }
                    else
                    {
                        methodEmitter.EmitAddQueryParameter(parameter, serializationMethods.ResolveQuery(QuerySerializationMethod.Default));
                    }
                }
            }
        }
 private void GenerateMethodProperties(MethodEmitter methodEmitter, List <EmittedProperty> emittedProperties, ResolvedSerializationMethods serializationMethods)
 {
     foreach (var property in emittedProperties)
     {
         // We've already validated these
         if (property.PropertyModel.HeaderAttribute != null)
         {
             methodEmitter.EmitAddHeaderProperty(property);
         }
         else if (property.PropertyModel.PathAttribute != null)
         {
             methodEmitter.EmitAddPathProperty(
                 property,
                 serializationMethods.ResolvePath(property.PropertyModel.PathAttribute.Attribute.SerializationMethod));
         }
         else if (property.PropertyModel.QueryAttribute != null)
         {
             methodEmitter.EmitAddQueryProperty(
                 property,
                 serializationMethods.ResolveQuery(property.PropertyModel.QueryAttribute.Attribute.SerializationMethod));
         }
         else if (property.PropertyModel.HttpRequestMessagePropertyAttribute != null)
         {
             methodEmitter.EmitAddHttpRequestMessagePropertyProperty(property);
         }
     }
 }