publicT ObjectToEntity<T>(object asObject) where T:new(){//创建实体对象实例var t = Activator.CreateInstance<T>();// user userModel = new UserOperation().ConvertObject<user>(obj);
IDictionary<string, object> iDictionary =((IDictionary<string, object>)asObject);//查找实体类属性是否和object属性相同foreach(var info intypeof(T).GetProperties()){if(iDictionary.ContainsKey(info.Name)){//赋值给实体类
info.SetValue(t, iDictionary[info.Name],null);}}return t;}