[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?
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.