Esempio n. 1
0
    protected List <T> GetList <T>(string key, MyHttpMethod myHttpMethod = MyHttpMethod.POST)
    {
        List <T> list = new List <T>();

        string rtn = GetString(key, myHttpMethod);

        if (rtn == null)
        {
            return(list);
        }

        foreach (var item in rtn.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries))
        {
            T tmp = default(T);
            if (typeof(T).Equals(typeof(string)))
            {
                list.Add((T)Convert.ChangeType(item, typeof(T)));
            }
            else
            {
                if (TryParse(item, out tmp))
                {
                    list.Add(tmp);
                }
            }
        }

        return(list);
    }
Esempio n. 2
0
    protected T GetNumber <T>(string key, MyHttpMethod myHttpMethod = MyHttpMethod.POST)
    {
        string rtn = GetString(key, myHttpMethod);

        if (rtn == null)
        {
            return(default(T));
        }

        T tmp = default(T);

        TryParse(rtn, out tmp);

        return(tmp);
    }
Esempio n. 3
0
    protected string GetString(string key, MyHttpMethod myHttpMethod = MyHttpMethod.POST)
    {
        string rtn = "";

        switch (myHttpMethod)
        {
        case MyHttpMethod.GET:
            rtn = HttpContext.Current.Request.QueryString[key];
            break;

        case MyHttpMethod.POST:
            rtn = HttpContext.Current.Request.Form[key];
            break;
        }

        if (rtn == null)
        {
            return("");
        }

        return(HttpUtility.HtmlEncode(rtn.Trim()));
    }