I have got below two public properties in my DataContract class.
I want to use this in client side. But I don’t want to return this through the service. Don’t I need DataMember Attribute for MyDateString?
[DataMember]
public DateTime MyDate { get; set; }
public string MyDateString
{
get
{
return MyDate.ToString("dd/MM/yyyy");
}
}
You need
[DataMember]only on members that you want serialized. SinceMyDateStringwill function as expected without being serialized (the backing property MyDate, on which MyDateString depends, is already serialized), you don’t need it on that property.