0
votes
[DataContract]
public class Credentials
{
    [DataMember]
    public string UserName {get;set;}
    public string Password {get;set;}
}

[DataContract]
public class User
{
    [DataMember]
    public Credentials Credentials {get;set;} 
}

In the above scenario, since Credentials is decorated with the DataMember attribute, is it necessary to decorate the Credentials class with DataContract and it's members with the DataMember attribute?

1

1 Answers

3
votes

Yes, you should mark up all classes used in the hierarchy with the appropriate DataContract/DataMember attributes.

Note that in your Credentials class you need to add a [DataMember] to the Password property as well.