从动态类型获取属性
我有一个动态类型
var f = context.ExecuteStoreQuery<dynamic>("CALL iv_sp_computersbyday();
,我现在如何知道动态 tuype 返回了哪些属性???我无法通过动态反思来访问。
i have a dynamic type
var f = context.ExecuteStoreQuery<dynamic>("CALL iv_sp_computersbyday();
how i can now what properties have the dynamic tuype returned??? i cant acces by reflection on the dynamic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不熟悉 ExecuteStoreQuery 但使用动态关键字和对象实际上是动态对象之间有区别。如果它是一个静态对象,只是转换为动态对象,那么反射就可以正常工作。如果它是动态对象,那么反射将返回方法,而不是您期望的方法。通常,动态对象将有某种方法来查询用于处理实现的参数,例如,从
DynamicObject
继承的事物通常实现GetDynamicMemberNames
,然后具有调用方法像TryGetMember
一样动态地进行。一旦有了成员名称,就有更通用的方法来执行动态绑定,但与 DLR CallSites 和 Binder 一起使用可能有点麻烦,尽管有一些简单的静态方法将所有 DLR 内容封装在开源框架中< a href="http://code.google.com/p/impromptu-interface/" rel="nofollow">即席界面。I'm not familiar with ExecuteStoreQuery but there is a difference between using the dynamic keyword and the object actually being a Dynamic Object. If it's a static object that is just cast as dynamic, then reflection will work just fine. If it's a Dynamic Object then reflection will return methods just not the ones you'd be expecting. Generally a Dynamic Object will have some way to query the parameters that are used to handle the implementation, for example things that inherit from
DynamicObject
often implementGetDynamicMemberNames
and then has methods to invoke dynamically likeTryGetMember
. There are more general ways to do the dynamic binding once you have member names but it can be a little much to use with the DLR CallSites and Binders, although there are some simple static methods that encapsulate all the DLR stuff in the open source framework Impromptu-Interface.