Ejemplo n.º 1
0
        public object DeserializeFromQueryString(Type type, NameValueCollection q)
        {
            if (DeserializeFromQueryStringOverride != null)
            {
                var e = new DeserializeFromQueryStringEventArgs {
                    Type = type, QueryString = q
                };
                DeserializeFromQueryStringOverride(e);
                if (e.Handled)
                {
                    return(e.Result);
                }
            }
            var prm = Activator.CreateInstance(type);

            foreach (string key in q)
            {
                var    sValue = q[key];
                object value  = sValue;
                var    pe     = prm.GetType().GetProperty(key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
                if (pe.PropertyType != typeof(string))
                {
                    value = Convert.ChangeType(sValue, pe.PropertyType);
                }
                pe.SetValue(prm, value);
            }
            return(prm);
        }
Ejemplo n.º 2
0
 public object DeserializeFromQueryString(Type type, NameValueCollection q)
 {
     if (DeserializeFromQueryStringOverride != null)
     {
         var e = new DeserializeFromQueryStringEventArgs { Type = type, QueryString = q };
         DeserializeFromQueryStringOverride(e);
         if (e.Handled)
             return e.Result;
     }
     var prm = Activator.CreateInstance(type);
     foreach (string key in q)
     {
         var sValue = q[key];
         object value = sValue;
         var pe = prm.GetType().GetProperty(key, BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public);
         if (pe.PropertyType != typeof(string))
         {
             value = Convert.ChangeType(sValue, pe.PropertyType);
         }
         pe.SetValue(prm, value);
     }
     return prm;
 }