在数据协定中定义必须是属性的成员

本文关键字:属性 成员 定义 数据 | 更新日期: 2023-09-27 18:22:34

好吧,我相信这一定非常容易,但我找不到关于这件事的信息。

此外,这是我第一次使用WCF,所以如果我对事物的理解有点慢,请对我宽容一点。

假设我有这类

[DataContract]
public class whatever {
    [DataMember]
    public string whateverName;
    [DataMember]
    public string whateverId;
}

这将序列化为:

<whatever>
    <whateverName></whateverName>
    <whateverId></whateverId>
</whatever>

如何更改它以进行以下序列化?

<whatever whateverName="" whateverId="" />

在数据协定中定义必须是属性的成员

您可以使用下面提到的代码,如

[DataContract]
public class whatever
{
  [XmlAttribute]
  public string whateverName;
  [XmlAttribute]
  public string whateverId;
}