Example #1
0
        public static void  GetEntitySearchPars <T>(this object thisObj, HttpContext context)
        {
            var request   = context.Request.Form;
            var getRequst = context.Request.Params;
            var type      = typeof(T);
            var pis       = FastType.Get(type).Setters;

            foreach (var p in pis)
            {
                if (request.AllKeys.Contains(p.Name, StringComparer.Create(Thread.CurrentThread.CurrentCulture, true)))
                {
                    var requestValue = request[p.Name];
                    p.SetValue(thisObj, requestValue.ConventToType(p.Info.PropertyType));
                }
                else if (getRequst.AllKeys.Contains(p.Name, StringComparer.Create(Thread.CurrentThread.CurrentCulture, true)))
                {
                    var requestValue = getRequst[p.Name];
                    p.SetValue(thisObj, requestValue.ConventToType(p.Info.PropertyType));
                }
            }
        }
Example #2
0
        public static IDictionary <string, object> ToDictionary(this object value)
        {
            IDictionary <string, object> dictionary = null;

            if (value.GetType() == typeof(Dictionary <string, object>))
            {
                dictionary = value as Dictionary <string, object>;
            }
            else
            {
                dictionary = new Dictionary <string, object>();
                FastType fastType = FastType.Get(value.GetType());
                fastType.Getters.ForEach(getter =>
                {
                    string name = getter.Name;
                    if (!name.IsNullOrEmpty())
                    {
                        object val = getter.GetValue(value);
                        dictionary.Add(name, val);
                    }
                });
            }
            return(dictionary);
        }