域属性作为元素并隐藏默认值属性
我有两个问题
- 如何实现以下目标,我有一个名为“Property”的域类 - Property 有两个属性“Type”和“Value”,目前正在序列化如下:
<属性类型=“TestType”><值>TestValue<值><属性>
我需要将其格式化为
<Property Type="TestType">TestValue</Property>
但我不确定如何?我已经设置了 Value 来表示一个元素,这确实解释了为什么它有自己的标签,但我不想要它们。
- 我有另一个类 - Parameter - 它具有 IsCollection ( bool ) 属性,我希望 IsCollection 属性仅在设置为 true 时才序列化,这可能吗?
否则
<Parameter Name="Foo" IsCollection="true" />
<Parameter Name="Foo" />
谢谢菲尔
I have two questions
- How do I achieve the following, I have a domain class called 'Property' - Property has two properties 'Type' and 'Value' it is currently being serialized as the following:
<Property Type="TestType"><Value>TestValue<Value><Property>
I need it to format as
<Property Type="TestType">TestValue</Property>
but I am not sure how? I have set Value to represent an Element, which does explain why it gets it's own tags but I don't want them.
- I have another class - Parameter - it has a property of IsCollection ( a bool ) , I would like the IsCollection attribute to be serialized only when it is set to true, is this possible?
i.e
<Parameter Name="Foo" IsCollection="true" />
otherwise
<Parameter Name="Foo" />
Thanks Phill
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否有效,但在 DSL 资源管理器中,找到 Serializer 类,您可以将其标记为自定义。如果您进行转换和编译,您将收到一堆错误,表明您需要提供自己的自定义序列化程序。我相信您可以将这些自定义和其他内容放在那里,尽管这可能比您想要的更多工作。
I'm not sure if this will work or not, but in the DSL explorer, find the classes Serializer and you can mark it as custom. If you transform and compile you'll get a bunch of errors that indicate you need to provide your own custom serializer. I believe that you can put these customizations and other in there, though it may be more work than you are looking for.