将对象实例模型实施到 PropertyGrid

发布于 2024-08-05 08:38:34 字数 839 浏览 11 评论 0原文

我正在构建一个 GUI 应用程序,它将作为 XML 配置文件的前端。

XML 结构定义了一组对象实例。即,应在使用应用程序(Windows 服务)中实例化的类型名称和属性值。

因此共有三层:

ConfigurationObject <--> ComponentObjects <--> PropertyGrid

ConfigurationObject 序列化为 Windows 服务的正确 XML 格式。 ComponentObjects 与 Windows 服务使用的类型相同。

我遇到的问题是确定保持所有三层同步的最佳方法。

我的第一个实现是在各个属性发生更改时更新它们。然而,当我需要将复杂对象更新到 UI 时,这种方法效果不佳(尽管我相信我现在知道问题是什么),

我当前的方法涉及使用 TypeConverters 在 ConfigurationObjectConfigurationObject 之间进行转换。 code>ComponentObjects 工作得很好,直到我意识到我当前的逻辑忽略了 BrowseableAttribute (因为我在转换为 ComponentObject 时只是迭代了所有 ComponentObject 属性) code>ConfigurationObject)

因此,在我花更多时间研究当前的方法之前,我想确保我走在正确的轨道上。有没有更简单的方法?在这种情况下我可以使用一些模型/设计模式吗?

谢谢, 卡尔

I am building a GUI application that will be the front-end for an XML configuration file.

The XML structure defines a set of object instances. That is, type names, and property values that should be instantiated in the consuming application (windows service).

So there are three layers:

ConfigurationObject <--> ComponentObjects <--> PropertyGrid

The ConfigurationObject serializes into the proper XML format for the windows service. The ComponentObjects are the same types that are used by the windows service.

The problem I am having is determining the best way to keep all three layers in sync.

My first implementation I would update individual properties when they were changed. However this approach didnt work very well when I need to update complex objects to the UI (Although I believe I know what the problem was now)

My current approach involves using TypeConverters to convert between the ConfigurationObject and the ComponentObjects which works well until a realized that my current logic is ignoring the BrowseableAttribute (since i simply iterate over all the ComponentObject properties when converting to a ConfigurationObject)

So before I spend anymore time on my current approach I want to be sure that I am on the right track. Is there a simpler approach? IS there some model/design pattern I can use in such a situation?

Thanks,
Karl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

辞别 2024-08-12 08:38:34

我能够找出问题中缺失的部分。

我为 ConfigurationObject 创建了一个 TypeDescriptionProvider,该提供程序用于在 ComponentObjects 属性和 ConfigurationObject 之间进行映射这些相同属性的表示。

ComponentObjectsTypeConverter 进行装饰,可以在 String 之间进行转换。

真正的关键是将 ConfigurationObject 分配给 PropertyGrid,而不是 >组件对象

I was able to figured out the missing pieces to my problem.

I Created a TypeDescriptionProvider for the ConfigurationObject this provider was used to map between the ComponentObjects Properties and the ConfigurationObject's representation of those same properties.

The ComponentObjects were decorated with TypeConverters which converted to and from String's

The real key was to assign the ConfigurationObject to the PropertyGrid and not the ComponentObjects.

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