Ejemplo n.º 1
0
        internal override HttpContent Bindbody(RequestCreContext requestCreContext)
        {
            List <KeyValuePair <String, String> > keyValues = new List <KeyValuePair <String, String> >();

            if (this.parameterWraps.Count == 0)
            {
            }
            this.parameterWraps.ForEach(x =>
            {
                string valueStr;
                if (TypeReflector.IsComplextClass(x.Parameter.ParameterType))
                {
                    List <KeyValuePair <string, object> > valuePairs =
                        DeconstructUtil.Deconstruct(requestCreContext.ParameterValues.Value[x.Parameter.Position]);
                    valuePairs.ForEach(kp =>
                    {
                        valueStr = x.Serial(kp.Value);
                        keyValues.Add(new KeyValuePair <string, string>(kp.Key, valueStr));
                    });
                }
                else
                {
                    valueStr = x.Serial(requestCreContext);
                    valueStr = valueStr ?? "";
                    keyValues.Add(new KeyValuePair <string, string>(x.DataName, valueStr));
                }
            });

            FormUrlEncodedContent formContent = new FormUrlEncodedContent(keyValues);

            return(formContent);
        }
Ejemplo n.º 2
0
 internal override void SaveToParameterContext(ParameterWrapContext parameterItem)
 {
     if (TypeReflector.IsComplextClass(parameterItem.Parameter.ParameterType))
     {
         throw new NotSupportedException("暂时不支持复杂类型用于header、pathpara");
     }
     parameterItem.pathParaAttribute = this;
 }
Ejemplo n.º 3
0
        internal override HttpContent Bindbody(RequestCreContext requestCreContext)
        {
            StringBuilder stringBuilder = new StringBuilder();

            Newtonsoft.Json.JsonTextWriter jsonWriter = new JsonTextWriter(new StringWriter(stringBuilder));
            jsonWriter.Formatting = Formatting.Indented;
            if (this.parameterWraps.Count == 1)
            {
                ParameterWrapContext parameterWrapContext = this.parameterWraps[0];
                string valueStr = parameterWrapContext.Serial(requestCreContext);
                if (valueStr == null)
                {
                    throw new LarkException("parameter value can not be null!");
                }
                if (string.IsNullOrEmpty(parameterWrapContext.Name) && TypeReflector.IsComplextClass(parameterWrapContext.Parameter.ParameterType))
                {
                    jsonWriter.WriteRaw(valueStr);
                }
                else
                {
                    jsonWriter.WriteStartObject();
                    jsonWriter.WritePropertyName(parameterWrapContext.DataName);
                    if (valueStr != null)
                    {
                        jsonWriter.WriteRawValue(valueStr);
                    }

                    jsonWriter.WriteEndObject();
                }
            }
            else if (this.parameterWraps.Count > 1)
            {
                jsonWriter.WriteStartObject();
                this.parameterWraps.ForEach(x =>
                {
                    jsonWriter.WritePropertyName(x.DataName);
                    object value    = requestCreContext.ParameterValues.Value[x.Parameter.Position];
                    string valueStr = x.Serial(value);
                    if (valueStr != null)
                    {
                        jsonWriter.WriteRawValue(valueStr);
                    }
                });
                jsonWriter.WriteEndObject();
            }
            else
            {
                // output :{}
                jsonWriter.WriteRaw("{}");
            }



            jsonWriter.Flush();
            StringContent stringContent = new StringContent(stringBuilder.ToString(), Encoding.UTF8, "application/json");

            return(stringContent);
        }
Ejemplo n.º 4
0
 internal override void SaveToParameterContext(ParameterWrapContext parameterItem)
 {
     if (TypeReflector.IsComplextClass(parameterItem.Parameter.ParameterType))
     {
         throw new NotSupportedException("暂时不支持复杂类型用于header、pathpara");
     }
     if (false == string.IsNullOrEmpty(Value))
     {
         throw new NotSupportedException("对于参数指定Value无效!");
     }
     parameterItem.HeaderAttributes.Add(this);
 }