开发者

WCF - DataMember as DataContract

I have a [DataContract] class Template declared as follows:

[DataContract]
public abstract class Template
{
    [DataMember]
    public virtual int? Id { get; set; }

    [DataMember]
    public virtual byte[] TemplateDoc { get; set; }

    [DataMember]
    public virtual string Title { get; set; }

    [DataMember]
    public virtual TemplateStatusInfo TemplateStatus { get; set; }
}

[DataContract]
public class Template开发者_运维百科StatusInfo
{
    [DataMember]
    public virtual List<string> ValidCodes { get; set; }

    [DataMember]
    public virtual List<string> InvalidCodes { get; set; }

    [DataMember]
    public virtual string TemplateError { get; set; }
}

As you can see Template has a [DataMember] child object 'TemplateStatusInfo'.

I just want to make sure if it is valid in WCF to declare child object with both attributes- [DataMember] as well as [DataContract].

I am not getting any compile time error.

Please guide.


It is correct what you have done. DataContract is applied to types, and DataMember to properties to specify if it should be included.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜