【问题标题】:Define members that must be attributes into the data contract定义必须是数据契约属性的成员
【发布时间】:2015-11-18 09:08:04
【问题描述】:

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

另外,这是我第一次使用 WCF,所以如果我理解的有点慢,请放轻松。

假设我有这门课

[DataContract]
public class whatever {

    [DataMember]
    public string whateverName;

    [DataMember]
    public string whateverId;

}

这将序列化为:

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

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

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

【问题讨论】:

标签: c# wcf datacontractserializer datacontract datacontracts


【解决方案1】:

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

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

  [XmlAttribute]
  public string whateverId;
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2016-01-05
  • 2015-09-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多