Page tree

LazyLoading

This parameter allows to instantiate objects only at the moment of their use. Here is an example of generated code :

Properties.LazyLoading (true/false)
        public List<dvd> Dvds
        {
            get
            {
                if ((dvdsField == null))
                {
                    dvdsField = new List<dvd>();
                }
                return dvdsField;
            }
            set
            {
				...
            }
        }

PropertyNameSpecified

Specified Conditional Serialization Pattern allows to exclude properties during the serialization process.

This parameter is used to generate additional properties which are used to determine whether a property should be serialized or not. There are several possibilities:



NoneNo such property generated
Specified

Generates a property ([PropertyName]Specified) that allows to indicate if a property must be taken into account in the serialization. In the example below if IsValidSpecified is set to true, the IsValid property will be taken into the serialization process. Otherwise the property will be ignored.

        public int PublishYear
        {
            get
            {
                return _publishYear;
            }
            set
            {
                _publishYear = value;
            }
        }

        [XmlIgnore()]
        public bool PublishYearSpecified
        {
            get
            {
                return _publishYearSpecified;
            }
            set
            {
                _publishYearSpecified = value;
            }
        }

In the example below, the code shows that it is necessary for each of the properties to implicitly specify that the serializer must include the property :

            DvdCollection collectionDvd = new DvdCollection();
            dvd newdvd = new dvd();
            newdvd.PublishYear = 2000;
            newdvd.PublishYearSpecified = true;
            collectionDvd.Dvds.Add(newdvd);
            collectionDvd.DvdsSpecified = true;
            collectionDvd.SaveToFile(@"c:\temp\dvds.xml");
  • No labels