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); }
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); } }