Reputation: 641
Is there any way to prevent DataContractSerializer
's Deserialize to ignore missing values and keep deserializing the rest of the data, instead of abandoning everything, throwing an Exception and returning NULL
?
I'm actively building the applicaton, so naturally its objects get new fields added quite frequently, and the further along it gets, the more pain it is to have to re-enter all the data every time any object type gets an extra field.
Upvotes: 3
Views: 1662
Reputation: 1536
You can use the IsRequired
Property of the DataMember
Attribute.
Example:
[DataContract]
public class Data
{
[DataMember]
public string Required { get; set; }
[DataMember(IsRequired=false)]
public string? NotRequired { get; set; }
}
Upvotes: 1