Skip to content

Custom Properties

Steve Ives edited this page Mar 30, 2020 · 1 revision

Harmony Core Logo

Adding Custom Properties to a Model

Harmony Core allows developers to extend code generated data models by adding custom properties. One common use case for this capability is to add "calculated" properties, or other properties that might be useful to a consumer of the data.

  • If the affected data model class has not already been customized via the addition of a custom partial class, then do so.

    For example, to customize a data model named Customer we recommend you add a source file named Customer.Custom.dbl that initially containins:

    namespace Services.Models
    
        public partial class Customer
    
    
        endclass
    
    endnamespace
    
  • Add a property to the custom data object partial class to represent the custom property.

    • Add a getter method to the property and add code that returns the custom property value.
    • Add a setter method to the property. If it is valid for the value of the custom property to be updated then have the setter method update the value, otherwise have the setter method throw an exception.

    For example, you might add a property like this:

    namespace Services.Models
    
        public partial class Customer
    
            public property AvailableCredit, decimal
                method get
                proc
                    mreturn this.CreditLimit - this.AccountBalance
                endmethod
                method set
                proc
                    throw new ApplicationException("Property AvailableCredit may not be updated.")
                endmethod
            endproperty
    
        endclass
    
    endnamespace
    
  • If the affected data model metadata class has not already been customized via the addition of a custom partial class, then do so.

    For example, to customize a metadata class named CustomerMetaData we recommend you add a source file named CustomerMetaData.Custom.dbl that initially containins:

    namespace Services.Models
    
        public partial class CustomerMetaData
    
    
        endclass
    
    endnamespace
    
  • If the custom metadata class does not already contain a method named InitializeCustomFields then add one, like this:

    namespace Services.Models
    
        public partial class CustomerMetaData
    
            private method InitializeCustomFields, void
            proc
    
            endmethod
    
        endclass
    
    endnamespace
    
  • Add code to the InitializeCustomFields method to add the definition of the custom field to the metadata class. For example:

    namespace Services.Models
    
        public partial class CustomerMetaData
    
            private method InitializeCustomFields, void
            proc
               AddFieldInfo("AvailableCredit","DECIMAL",8,0,2,false)
            endmethod
    
        endclass
    
    endnamespace
    

The parameters to the AddFieldInfo call are as follows:

  • Property name
  • Data type name. Supported values are ALPHA, BINARY, DATE, DECIMAL, IMPLIED, INTEGER, JULIAN, TIME, USER ALPHA, USER DATE, USER NUMERIC, TAG_LITERAL, DATAOBJECT, COLLECTION and COMPOSITE.
  • Field size (bytes)
  • Position in record
  • Number of decimal places (or zero)
Clone this wiki locally