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;}
前端js传json对象,c#后端接收下面展示一些 内联代码片。工具类部分 public T ObjectToEntity<T>(object asObject) where T : new() { //创建实体对象实例 var t = Activator.CreateInstance<T>(); // user userModel = new UserOperation().Conver