如何在 .NET 4 中重写动态对象的 PropertyDescriptor.GetValue 和 PropertyDescriptor.SetValue
我们使用DynamicObject
进行动态属性创建,但随后我们想要使用PropertyGrid
来显示此属性并编辑它们。
首先,我找到了这篇文章,以及这篇一个。我尝试使用第二篇文章的代码,但以更通用的方式,基本上用变量替换所有方法名称常量。但问题是VS2010找不到CSharpGetMemberBinder
类型。
有人知道如何更换吗?或者最好的方法是什么?
We are using DynamicObject
for dynamic properties creation, but then we want to use PropertyGrid
to show this properties and edit them.
Firstly, I found this article, and this one. I try to use second article code, but in more generic fashion, basically to replace all methods names constants with variables. But the problem is that VS2010 can't find CSharpGetMemberBinder
type.
Does someone know how to replace it? or what is the best approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以简单地转换为 IDictionary 并设置/检索值,而不是使用该文章的 Helper 类(已过时):
编辑:这可能仅适用于 ExpandoObjects 的情况,这就是本文所使用的。如果您创建了您自己的动态类具有不同的支持,您可能需要更改它。
Instead of using that article's Helper class (which is outdated), you can simply cast to IDictionary and set / retrieve the values:
Edit: This may only work in the case of ExpandoObjects, which was what the article was using.. if you created your own dynamic class with a different backing, you may need to change this.
您可以使用开源框架Dynamitey,它可以让您调用任何<的动态属性/em>
IDynamicMetaObjectProvider
按字符串名称。You can use the open source framework Dynamitey it lets you invoke dynamic properties of any
IDynamicMetaObjectProvider
by string name.它应该类似于:
关联的集合类似于:
It should be something like:
and the associated set would be something like: