更改属性的序列化内容

发布于 2024-08-27 03:59:50 字数 257 浏览 4 评论 0原文

我想我已经知道这个问题的答案,但我找不到任何明确说明的内容,因此我的问题是 - 我想确保我没有错过任何技巧。

使用 DataContractSerializer 或 XmlSerializer,是否有任何方法可以更改公共属性的序列化方式?我有一个 Enum 属性,我希望将其序列化为 int,以便通过线路发送其值,而不是文本表示形式它的价值。是否可以使用属性来做到这一点,或者我必须编写自己的序列化程序?

谢谢 :)

I think i already know the answer to this, but i cannot find anything that states it definitively, hence my question - i want to make sure i am not missing a trick.

Using the DataContractSerializer or the XmlSerializer, is there any way to change what a pulic property is serialized as? I have a property that is an Enum, and i would like it to be serialized as an int, so that its value is sent across the wire instead of a text representation of its value. Is it possible to do this using attributes, or will i have to write my own serializer?

Thanks :)

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

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

发布评论

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

评论(1

从此见与不见 2024-09-03 03:59:50

可能这就是您正在寻找的内容: XmlEnum。您可以指定在序列化期间应为每个枚举值保存哪些内容。

Probably that's what are you looking for: XmlEnum. You can specify what should be saved during serialization for each enum value.

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