将DataMember添加到DataContract的其他名称空间 [英] Adding a DataMember to a different namespace to the DataContract

查看:80
本文介绍了将DataMember添加到DataContract的其他名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用XmlSerializer,我可以将成员设置为与父类型不同的名称空间.

With the XmlSerializer I can have my members in different namespaces to the parent type.

我可以对DataContractSerializer做同样的事情吗?

Can I do the same thing with DataContractSerializer?

我想要以下XML:

<h:Type xmlns:h="http://schemas.e.com/WebServices"
    xmlns="http://schemas.e.com/WebServices">
  <Member xmlns="http://schemas.e.com/CoreTypes">0</Member>
</h:Type>

使用DataContractSerializer可以吗?

推荐答案

您可以在不同的命名空间中定义子数据合同,并将其用作另一个数据合同的成员,但是您无法控制各个成员的名称和/或形状. DataContractSerializer并不是要替换XmlSerializer来对XML的形状"进行细粒度控制.

You can define subdatacontracts in different namespaces and use them as members of another datacontract, but you can't control the individual member names and/or shapes. The DataContractSerializer isn't intended to replace XmlSerializer for fine-grained control of the "shape" of your XML.

这篇关于将DataMember添加到DataContract的其他名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆