IDynamicMetaObjectProvider 最简单的实现是什么?
我有这种情况...
1.- 我提供一个“动态表”,供用户定义字段。每个动态表将根据需要拥有尽可能多的行/记录,但字段定义是集中的。
2.- 我的动态行/记录类继承自 .NET DLR DynamicObject 类,底层存储是与定义字段适当关联的列表。一切正常!但是...
3.- 因为我需要序列化内容,而 DynamicObject 不可序列化,所以当需要动态成员访问时,我被迫生成并携带动态对象。但这是丑陋且多余的。
所以,我需要自己实现IDynamicMetaObjectProvider来一起实现动态访问和序列化。
谷歌搜索/搜索失败后,我请求你的帮助...... 有人可以提供一个很好的例子(或相关链接)来做到这一点吗?
I have this scenario...
1.- I'm providing a "Dynamic Table" for wich users can define Fields. Each Dynamic Table will have as many rows/records as needed, but the Field definitions are centralized.
2.- My Dynamic Row/Record class was inherited from the .NET DLR DynamicObject class, and the underlying storage was a List appropriately associated to the defining fields. Everything works fine! BUT...
3.- Because I need to Serialize the content, and DynamicObject is not Serializable, I was forced to generate and carry a Dynamic Object when dynamic member access is required. But this is ugly and redundant.
So, I need to implement IDynamicMetaObjectProvider myself to achieve dynamic access and serialization together.
After googling/binging unsuccessfully I ask for your help...
Can anybody please give a good example (or related link) for doing that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,您正在重新发明 ExpandoObject 类。请考虑将这些集合用于您的实施。
Sounds to me like you are re-inventing the ExpandoObject class. Consider a collection of those for your implementation instead.
解决方案是实施自定义序列化。
实现 ISerialized 接口,以及反序列化构造函数。
实现 IDynamicMetaObjectProvider 花费的时间更少。
The solution was to implement Custom Serialization.
Implement the ISerializable interface, plus the deserialization constructor.
It takes less time that implement IDynamicMetaObjectProvider.