DSL 将根元素添加到序列化中
我正在寻求帮助来实现以下目标
该图代表一辆汽车,
当我查看 XML 时,用户可以添加引擎和颜色,它看起来像这样:
<Car>
<Engine>BigEngine</Engine>
<Colour>Pink</Colour>
</Car>
我想做的是将汽车包装在“车辆”内,即
<Vehicle>
<Car>
<Engine>BigEngine</Engine>
<Colour>Pink</Colour>
</Car>
</Vehicle>
我是不确定实现这一目标的最佳方法。 我希望将模型资源管理器和生成的 XML 包装在“车辆”中,但出于所有其他意图和目的,用户仅使用汽车
信息:Visual Studio 2010、C# 和 DSL SDK for 2010
I am looking for help to achieve the following
The Diagram represents a car, users can add engine and colour
when I view the XML it looks like this:
<Car>
<Engine>BigEngine</Engine>
<Colour>Pink</Colour>
</Car>
What I would like to do is to wrap the car inside 'vehicle', i.e
<Vehicle>
<Car>
<Engine>BigEngine</Engine>
<Colour>Pink</Colour>
</Car>
</Vehicle>
I am not sure of the best way to achieve this. I want the model explorer and the generated XML to be wrapped in 'vehicle' but for all other intents and purposes the user is working with a car only
Info: Visual Studio 2010, C# and DSL SDK for 2010
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经通过以下方法解决了这个问题。 我双重派生 Car 类,在 Car 序列化器中我正在执行以下操作:
编写额外的元素:
为了能够读回此内容,我重写了 SerializationHelper 中的 Car LoadModel 方法以及它在哪里获取我正在阅读的读者直到我到达汽车。
......
I have fixed this by the following. I am double deriving the Car class and in the Car serializer I am doing this:
Writing the extra elements:
To be able to read this back in I am overriding the Car LoadModel method in the SerializationHelper and where it is getting the reader I am reading the elements until I get to Car.
....
....
我会尝试两种不同的方法:
第一种:覆盖 DSL 包类 DocData
在 DocData.cs 文件和重写方法中
,然后我将创建包装器,
然后在 DocData.cs 中重写
,并在调用基本方法
base.OnDocumentLoading(e);
之前,我将从文件中删除。第二:在 DSL Explorer 下,转到 XML Serialization Behaviour 并设置 Car Domain Class“Is Custom = true”。
这个解决方案并不简单,但也不像乍看起来那么复杂。 您必须定义每个方法,但对于每个自定义方法,您可以调用名为“DefaulMethod”的 DSL 生成方法,该方法具有默认的 DSL 序列化器行为。
我目前使用的是 VS 2005,所以有些事情可能已经改变了......
I would try two different approaches:
1st: override DSL Package class DocData
In DocData.cs file and override method
and then I would create the wrapper
afterwards I'd override in DocData.cs
and before calling the base method
base.OnDocumentLoading(e);
i would delete from the file.2nd: Under DSL Explorer go to XML Serialization Behaviour and set Car Domain Class "Is Custom = true".
This solution is not straightforward but it's not as complicated as it seems at the first place. You'll must define every single method but for each custom method you can call a DSL generated method called "DefaulMethod" which has the default DSL serializer behaviour.
I am currently using VS 2005, so some things might have changed...