Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Answers


Can I prevent a specific datamember from being deserialized?

Serializes and deserializes an instance of a type into an XML stream or document using a supplied data contract.

If you want to ignore some class fields or properties from serializing:

1.  IF you are using [DataContract], then remove the [DataMember] attribute  for the property.
2.  If you are using [Serializable], then add [NonSerialized] in front of the field for the property.
3.  If you haven't decorated your class, then you should add [IgnoreDataMember] attribute to the property.

  public class Product
    {
        [
DataMember(Name= "Id")]
       
public int Id { get; set; }
       
        [
DataMember(Name= "ProductCode")]
       
public string ProductCode { get; set; }
 
        [
DataMember]
       
public string Description{ get; set; }
       
       
// ignore language specific detail from serializing.

        public string LanguageSpecificDescription{ get; set; }
 
        [
DataMember]
       
public ProductCetagoery ProductType { get; set; }
       
   }

Share your answer


Share as a guest

Please subscribe me to the CodeChef4U.

By creating your new answer, you agree to the privacy policy and terms of service.