Deserialization of the DataContractSerializer description completes completely if only one value is missing

Is there a way to prevent DataContractSerializer

Deserialize from ignoring missing values ​​and keeping the rest of the data deserialized, instead of discarding everything by throwing an Exception and returning NULL

?

I am actively creating the app, so naturally its objects add new fields, added quite often, and the further it goes, the more it hurts to re-enter all the data every time any type of object gets an extra field.

+3


source to share


1 answer


You can use IsRequired

attribute property DataMember

.

http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute_properties.aspx



Example:

[DataContract]
public class Data
{
     [DataMember]
     public string Required { get; set; }

     [DataMember(IsRequired=false)]
     public string? NotRequired { get; set; }
}

      

+1


source







All Articles