IDynamicMetaObjectProvider 最简单的实现是什么?

发布于 2024-09-01 01:38:57 字数 365 浏览 6 评论 0原文

我有这种情况...

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

徒留西风 2024-09-08 01:38:57

Sounds to me like you are re-inventing the ExpandoObject class. Consider a collection of those for your implementation instead.

暗藏城府 2024-09-08 01:38:57

解决方案是实施自定义序列化。
实现 ISerialized 接口,以及反序列化构造函数。

实现 IDynamicMetaObjectProvider 花费的时间更少。

The solution was to implement Custom Serialization.
Implement the ISerializable interface, plus the deserialization constructor.

It takes less time that implement IDynamicMetaObjectProvider.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文