@@ -179,47 +179,47 @@ public static object CreateObjectByTypeByCodeFirst(IFreeSql fsql, Type type,
179179 return istance ;
180180 }
181181
182- //设置动态对象的属性值,使用表达式目录树
183- public static object CreateObjectByType ( Type type , Dictionary < string , object > porpertys )
184- {
185- if ( type == null )
186- return null ;
187- object istance = Activator . CreateInstance ( type ) ;
188- if ( istance == null )
189- return null ;
190- //根据字典中的key确定缓存
191- var cacheKeyStr = string . Join ( "-" , porpertys . Keys . OrderBy ( s => s ) ) ;
192- var cacheKey = Md5Encryption ( cacheKeyStr ) ;
193- var dynamicDelegate = _delegateCache . GetOrAdd ( cacheKey , key =>
194- {
195- //表达式目录树构建委托
196- var typeParam = Expression . Parameter ( type ) ;
197- var dicParamType = typeof ( Dictionary < string , object > ) ;
198- var dicParam = Expression . Parameter ( dicParamType ) ;
199- var exps = new List < Expression > ( ) ;
200- var tempRef = Expression . Variable ( typeof ( object ) ) ;
201- foreach ( var pinfo in porpertys )
202- {
203- var propertyInfo = type . GetProperty ( pinfo . Key ) ;
204- if ( propertyInfo == null )
205- continue ;
206- var propertyName = Expression . Constant ( pinfo . Key , typeof ( string ) ) ;
207- exps . Add ( Expression . Call ( dicParam , dicParamType . GetMethod ( "TryGetValue" ) , propertyName , tempRef ) ) ;
208- exps . Add ( Expression . Assign ( Expression . MakeMemberAccess ( typeParam , propertyInfo ) ,
209- Expression . Convert ( tempRef , propertyInfo . PropertyType ) ) ) ;
210- exps . Add ( Expression . Assign ( tempRef , Expression . Default ( typeof ( object ) ) ) ) ;
211- }
182+ //// 设置动态对象的属性值,使用表达式目录树
183+ // public static object CreateObjectByType(Type type, Dictionary<string, object> porpertys)
184+ // {
185+ // if (type == null)
186+ // return null;
187+ // object istance = Activator.CreateInstance(type);
188+ // if (istance == null)
189+ // return null;
190+ // //根据字典中的key确定缓存
191+ // var cacheKeyStr = string.Join("-", porpertys.Keys.OrderBy(s => s));
192+ // var cacheKey = Md5Encryption(cacheKeyStr);
193+ // var dynamicDelegate = _delegateCache.GetOrAdd(cacheKey, key =>
194+ // {
195+ // //表达式目录树构建委托
196+ // var typeParam = Expression.Parameter(type);
197+ // var dicParamType = typeof(Dictionary<string, object>);
198+ // var dicParam = Expression.Parameter(dicParamType);
199+ // var exps = new List<Expression>();
200+ // var tempRef = Expression.Variable(typeof(object));
201+ // foreach (var pinfo in porpertys)
202+ // {
203+ // var propertyInfo = type.GetProperty(pinfo.Key);
204+ // if (propertyInfo == null)
205+ // continue;
206+ // var propertyName = Expression.Constant(pinfo.Key, typeof(string));
207+ // exps.Add(Expression.Call(dicParam, dicParamType.GetMethod("TryGetValue"), propertyName, tempRef));
208+ // exps.Add(Expression.Assign(Expression.MakeMemberAccess(typeParam, propertyInfo),
209+ // Expression.Convert(tempRef, propertyInfo.PropertyType)));
210+ // exps.Add(Expression.Assign(tempRef, Expression.Default(typeof(object))));
211+ // }
212212
213- var returnTarget = Expression . Label ( type ) ;
214- exps . Add ( Expression . Return ( returnTarget , typeParam ) ) ;
215- exps . Add ( Expression . Label ( returnTarget , Expression . Default ( type ) ) ) ;
216- var block = Expression . Block ( new [ ] { tempRef } , exps ) ;
217- var @delegate = Expression . Lambda ( block , typeParam , dicParam ) . Compile ( ) ;
218- return @delegate ;
219- } ) ;
220- var dynamicInvoke = dynamicDelegate . DynamicInvoke ( istance , porpertys ) ;
221- return dynamicInvoke ;
222- }
213+ // var returnTarget = Expression.Label(type);
214+ // exps.Add(Expression.Return(returnTarget, typeParam));
215+ // exps.Add(Expression.Label(returnTarget, Expression.Default(type)));
216+ // var block = Expression.Block(new[] { tempRef }, exps);
217+ // var @delegate = Expression.Lambda(block, typeParam, dicParam).Compile();
218+ // return @delegate;
219+ // });
220+ // var dynamicInvoke = dynamicDelegate.DynamicInvoke(istance, porpertys);
221+ // return dynamicInvoke;
222+ // }
223223
224224 /// <summary>
225225 /// 首字母小写
0 commit comments