使用linq查询获取动态属性名称 [英] Using linq query fetch dynamic property name
本文介绍了使用linq查询获取动态属性名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
地狱全部
i我正在使用
列表< ExpandoObject>
但如果我们使用linq那时候我不是获得房产
我尝试过:
<预> var grdfeatchobjlist =(List< ExpandoObject>)grdproductitem.ItemsSource;
var getlist = grdfeatchobjlist.Select(x => x.GetType()。GetProperty(batchId)== Txtbatchcode.Text.ToString());
解决方案
如果在编译时知道属性名称,则将ExpandoObject
强制转换为dyanmic
,并直接访问该属性:
var getlist = grdfeatchobjlist.Select(( dynamic x)= > x.batchId == Txtbatchcode.Text);
对于动态属性名称直到运行时才知道,将ExpandoObject
强制转换为IDictionary< string,object>
,然后使用索引器:
var getlist = grdfeatchobjlist.Select((IDictionary< string,object> x)= > x [ batchId] == Txtbatchcode.Text);
Hell All
i am using
List<ExpandoObject>
but if we use linq that time i am not getting property
What I have tried:
<pre> var grdfeatchobjlist = (List<ExpandoObject>)grdproductitem.ItemsSource;
var getlist = grdfeatchobjlist.Select(x => x.GetType().GetProperty("batchId") == Txtbatchcode.Text.ToString());
解决方案
If the property name is known at compile time, cast theExpandoObject
todyanmic
, and access the property directly:
var getlist = grdfeatchobjlist.Select((dynamic x) => x.batchId == Txtbatchcode.Text);
For a dynamic property name which isn't known until runtime, cast theExpandoObject
to anIDictionary<string, object>
, and use the indexer:
var getlist = grdfeatchobjlist.Select((IDictionary<string, object> x) => x["batchId"] == Txtbatchcode.Text);
这篇关于使用linq查询获取动态属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文