将对象实例模型实施到 PropertyGrid
我正在构建一个 GUI 应用程序,它将作为 XML 配置文件的前端。
XML 结构定义了一组对象实例。即,应在使用应用程序(Windows 服务)中实例化的类型名称和属性值。
因此共有三层:
ConfigurationObject <--> ComponentObjects <--> PropertyGrid
ConfigurationObject
序列化为 Windows 服务的正确 XML 格式。 ComponentObjects
与 Windows 服务使用的类型相同。
我遇到的问题是确定保持所有三层同步的最佳方法。
我的第一个实现是在各个属性发生更改时更新它们。然而,当我需要将复杂对象更新到 UI 时,这种方法效果不佳(尽管我相信我现在知道问题是什么),
我当前的方法涉及使用 TypeConverters 在 ConfigurationObject
和 ConfigurationObject
之间进行转换。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够找出问题中缺失的部分。
我为
ConfigurationObject
创建了一个TypeDescriptionProvider
,该提供程序用于在ComponentObjects
属性和ConfigurationObject
之间进行映射这些相同属性的表示。ComponentObjects
用TypeConverter
进行装饰,可以在 String 之间进行转换。真正的关键是将
ConfigurationObject
分配给 PropertyGrid,而不是>组件对象
。I was able to figured out the missing pieces to my problem.
I Created a
TypeDescriptionProvider
for theConfigurationObject
this provider was used to map between theComponentObjects
Properties and theConfigurationObject
's representation of those same properties.The
ComponentObjects
were decorated withTypeConverter
s which converted to and from String'sThe real key was to assign the
ConfigurationObject
to the PropertyGrid and not theComponentObjects
.