Business Numerators. Template

The Numerator generates the string value using the XafariObjectFormatter class to replace the format items in a particular string with various calculated elements including the sequence number (INDEX). The Template property is intended to specify the required format. The {0} parameter denotes an object that is subject to automatic numeration, {0:<INDEX>} is interpreted as the current value of the Numerator index.

XafariObjectFormatter provides flexible navigation through the properties of the persistent objects. For instance, the ComplexNumeration class exposes the Owner reference property referring to the ComplexNumerationReference class. The following code snippet and the image below demonstrate the case:

  • c#
  • VB

public class ComplexNumeration : BaseObject
{
  //...
  [Association("A-B")]
  public ComplexNumerationReference Owner
  {
    get
    {
      return this.GetPropertyValue<ComplexNumerationReference>("Owner");
    }
    set
    {
      SetPropertyValue("Owner", value);
    }
  }
}

Public Class ComplexNumeration
  Inherits BaseObject
  '...
  <Association("A-B")> _
Public Property Owner As ComplexNumerationReference
    Get
      Return Me.GetPropertyValue(Of ComplexNumerationReference)("Owner")
    End Get
    Set
      SetPropertyValue("Owner", value)
    End Set
  End Property
End Class

numerator_19

The ComplexNumeration Numerator is linked to the ComplexNumber property of the ComplexNumeration class; the Numerator's Template property is "COMPLEX_{0:<INDEX>}/{0:Owner.Name}".

numerator_20

The image below shows the values for the ComplexNumber property; the values are generated by the ComplexNumeration Numerator.

numerator_21

The Numerators support CustomNumericFormatStrings allowing to format the index value. The {0:<INDEX>, numericFormat} construction is used, where the required format is specified by numericFormat. For instance, if the Template property is "{0:<INDEX>, 000000}", the value that the Numerator returns is "000001".

numerator_73

Please note that DevExpress.ExpressApp.Model.ModelDefaultAttribute allows to customize the EditMask for the certain property. EditMask has higher priority than the format itself. The following code demonstrates the EditMaskNumber property decorated with the ModelDefault attribute:

  • c#
  • VB

public class EditMaskNumeration : BaseObject
{
  //...
  [ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(true)]
  [Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]
  public string EditMaskNumber
  {
    get
    {
      return this.GetPropertyValue<string>("EditMaskNumber");
    }
    set
    {
      SetPropertyValue("EditMaskNumber", value);
    }
  }
}

Public Class EditMaskNumeration
  Inherits BaseObject
  '...
  <ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(True)> _
<Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)> _
Public Property EditMaskNumber As String
    Get
      Return Me.GetPropertyValue(Of String)("EditMaskNumber")
    End Get
    Set
      SetPropertyValue("EditMaskNumber", value)
    End Set
  End Property
End Class

It is also important to remember that this property is processed by the Numerator which Template is "{0:<INDEX>,00000}". The resulting strings use the index while the format is defined by the EditMask.

numerator_22

Note

The complete sample project is available in BusinessNumerators. You can view the code used in this lesson in the BusinessNumerators.Module|BusinessObjects|Objects.cs file.

See also: