Properties

AutomaticProperties

Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. It is possible to activate this option in xsd2code++ to obtain a more compact code, which improves the readability of classes.

xsd2code++ automaticProperties

LazyLoading

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

Lazy initialization is a technique that defers the creation of an object until the first time it is needed. In other words, initialization of the object happens only on demand. Note that the terms lazy initialization and lazy instantiation mean the same thing—they can be used interchangeably. By taking advantage of lazy initialization, you can improve the application’s performance by avoiding unnecessary computation and memory consumption. In this article we’ll look at how we can perform lazy initialization in C# with xsd2code++.

To enable this feature, you must set it in the settings: PROPERTIES.LAZYLOADING (TRUE/FALSE)

LazyLoading in xsd2code++
public List<dvd> Dvds
{
    get
    {
        if ((dvdsField == null))
        {
            dvdsField = new List<dvd>();
        }
        return dvdsField;
    }
    set
    {
        ...
}
}

NotifyPropertyChanged


The INotifyPropertyChanged interface is used to notify clients, typically binding clients, that a property value has changed.

For example, consider a Person object with a property called FirstName. To provide generic property-change notification, the Person type implements the INotifyPropertyChanged interface and raises a PropertyChanged event when FirstName is changed.

For change notification to occur in a binding between a bound client and a data source, xsd2code++ generates the code that :

- Implement the INotifyPropertyChanged interface.

- Provide a change event à each time the value is changed or set to null.

public partial class RootSchemaCustomer : INotifyPropertyChanged
{
    #region Private fields
    private PurchaseOrderType _purchaseOrder;
    private static MessagePackSerializer _serializer;
    #endregion
 
    public RootSchemaCustomer()
    {
        _purchaseOrder = new PurchaseOrderType();
    }
 
    public PurchaseOrderType PurchaseOrder
    {
        get
        {
            return _purchaseOrder;
        }
        set
        {
            if ((_purchaseOrder == value))
            {
                return;
            }
            if (((_purchaseOrder == null)
                        || (_purchaseOrder.Equals(value) != true)))
            {
                _purchaseOrder = value;
                OnPropertyChanged("PurchaseOrder");
            }
        }
    }

PascalCaseProperty


PascalCase is a naming convention in which the first letter of each word in a compound word is capitalized. If you use this naming convention, you can activate it in your generated classes.

xsd2code++ PascalCase propoertiesXsd2Code++ takes care of injecting the necessary attributes to maintain compliance with the XML or JSON schema.


Private fields name & Prefix

Within the naming convention that you wish to adopt, you have the possibility to define if the private elements begin or end with :

  • StartWithUnderscore : private bool _isEnabled;
  • EndWithField : private bool isEnabledField;
  • StartWithCustomPrefix : private bool _p_isEnabled;

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:

None This feature is disabled
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;

VirtualProperties

Virtual properties behave like virtual methods, except for the differences in declaration and invocation syntax.
A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier.

public virtual PurchaseOrderType PurchaseOrder
{
    ...
}
public override PurchaseOrderType PurchaseOrder
{
    ...
}

Terms & privacy

Terms of uses · Privacy policy 

Contact

CodeNGine Technologies, 19 Avenue, de la gare, 34770 Gigean, France. SIRET: 85257252800010, VAT : FR 62852572528
codengine.technologies@xsd2code.com

About the company

CodeNGine Technologies is software company based in the South of France that provides an advanced productivity code generation tool to developers using XML and JSON


Copyright © 2021 CodeNGine Technologies