Esempio n. 1
0
        /// <summary>
        /// 根据HttpRequest,返回泛型T对象,
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static T Request2Entity <T>(HttpRequest request, T t)
        {
            if (t == null)
            {
                return(t);
            }
            T    tRtn = tRtn = ( T )Activator.CreateInstance(typeof(T));
            Type type = tRtn.GetType();

            System.Collections.Specialized.NameValueCollection nvc = request.Params;
            PropertyInfo[] pis = type.GetProperties();
            foreach (PropertyInfo pi in pis)
            {
                var value = nvc.Cast <string>()
                            .Where(key => key.ToUpper() == pi.Name.ToUpper())
                            .Select(key => nvc[key]);
                if (value.Count() > 0)
                {
                    string strValue = value.First().ToString();
                    pi.SetValue(tRtn, strValue);
                }
            }
            return(tRtn);
        }
 public static IEnumerable <string> AsEnumerable(this System.Collections.Specialized.NameValueCollection source)
 {
     TypeCheckEnumerable(source, s => s.AsEnumerable(), (s) => s[0]);
     return(source.Cast <string>());
 }
Esempio n. 3
0
 public static string Join(this System.Collections.Specialized.NameValueCollection collection, Func <string, string> selector, string separator)
 {
     return(String.Join(separator, collection.Cast <string>().Select(e => selector(e))));
 }