AddParameter() публичный Метод

public AddParameter ( string name, string value ) : void
name string
value string
Результат void
Пример #1
0
    public virtual HTTP.Request AddRequestInfo(HTTP.Request request)
    {
        Dictionary <string, object> requestBody = new Dictionary <string, object>();
        Type currentType = this.GetType();

        foreach (FieldInfo field in currentType.GetFields(BindingFlags.Public | BindingFlags.Instance))
        {
            object temp = field.GetValue(this);
            if (temp != null)
            {
                if (temp is ICollection)
                {
                    requestBody[field.Name] = temp;
                }
                else
                {
                    request.AddParameter(field.Name, System.Uri.EscapeDataString(temp.ToString()));
                }
                continue;
            }
            request.AddParameter(field.Name, "");
        }

        foreach (PropertyInfo prop in currentType.GetProperties(BindingFlags.Public))
        {
            MethodInfo getter = prop.GetGetMethod();
            if (getter != null)
            {
                object temp = getter.Invoke(this, null);
                if (temp != null)
                {
                    if (temp is ICollection)
                    {
                        requestBody[prop.Name] = temp;
                    }
                    else
                    {
                        request.AddParameter(prop.Name, temp.ToString());
                    }
                    continue;
                }
            }
            request.AddParameter(prop.Name, "");
        }

        if (requestBody.Count > 0)
        {
            request.SetBody(requestBody);
        }

        return(request);
    }