Serialize a property using System.ComponentModel.DefaultValueAttribute

ammar.dev

Member
Joined
Sep 21, 2015
Messages
8
Programming Experience
Beginner
Hello,

I try to serialize a n object to xml file.this object containt a property length
C#:
[System.Xml.Serialization.XmlAttributeAttribute()] 
        [System.ComponentModel.DefaultValueAttribute(1D)] 
        public double Length 
        { 
            get 
            { 
                return this.lengthField; 
            } 
            set 
            { 
                this.lengthField = value; 
            } 
        }

When i give the value 1 to this property it does not displayed. Despite when i tried to affect the value 1.65 or 1.75 it appeared
XML:
<Man1 Attribute1Person1="NameMan" Attribute2Person1="LastNameMan" length="1.65" />   
<Man2 Attribute1Person2="NameMan" Attribute2Person2="LastNameMan" />   
<Man3 Attribute1Person3="NameMan" Attribute2Person3="LastNameMan" length="1.55" />   
<Man4 Attribute1Person4="NameMan" Attribute2Person4="LastNameMan"  />

How can fix this problem to display Length=1 ?
 

Latest posts

Back
Top Bottom