Esempio n. 1
0
        public object GetNew(Type type, RouteData rd)
        {
            object newObj = Activator.CreateInstance(type);

            if (rd != null && rd.Values.ContainsKey("@id"))
            {
                string       idName = (Repository.Instance.Registered(type) as BasicRepository).GetIdName(type);
                PropertyInfo prop   = type.GetProperty(idName);
                prop.SetValue(newObj, ReflectionX.ChangeType(rd.Values["@id"], prop.PropertyType));
            }
            return(newObj);
        }
Esempio n. 2
0
        private object ConvertForField(Type type, string propertyName, object val)
        {
            Type propertyType = type.GetProperty(propertyName).PropertyType;

            if (val.GetType() != propertyType)
            {
                return(ReflectionX.ChangeType(val, propertyType));
            }
            else
            {
                return(val);
            }
        }