Services Model Wrappers. Code Samples

This page shows the examples of implementing various wrapper classes based on the described best practices.

A sample wrapper class for the IModelServicesNumerators node of the Services Model:

  • c#
  • c#(original)

[DomainComponent]
public class NumeratorsCfgObject : ServiceCfgObject<NumeratorsCfgObject, IModelServicesNumerators>
{
  // Default .ctor is necessary to be able to create objects by invoking
  // the NonPersistentObjectSpace.CreateObject() method.
  public NumeratorsCfgObject()
  {
  }
  [ModelDefault("Tooltip", "Default value for numerator 'Template' property")]
  [XafDisplayName("Template")]
  public string DefaultTemplate
  {
    get
    {
      return GetPropertyValue<string>(x => x.DefaultTemplate);
    }
    set
    {
      SetPropertyValue(x => x.DefaultTemplate, value);
    }
  }
  // The attribute is required to nested collection behave as aggregated collection
  //in UI and modification logic.
  [ModelDefault("Tooltip", "List of numerators")]
  [Aggregated]
  public IList<NumeratorCfgObject> Numerators
  {
    get
    {
      return GetCollection<NumeratorCfgObject, IModelServicesNumerator>(x => x.Numerators);
    }
  }
  //...
}

[DomainComponent]
 public class NumeratorsCfgObject : ServiceCfgObject<NumeratorsCfgObject, IModelServicesNumerators>
 {
 // Default .ctor is necessary to be able to create objects by invoking
 // the NonPersistentObjectSpace.CreateObject() method.
 public NumeratorsCfgObject() {}

 [ModelDefault("Tooltip", "Default value for numerator 'Template' property")]
 [XafDisplayName("Template")]
 public string DefaultTemplate
 {
     get { return GetPropertyValue<string>(x => x.DefaultTemplate); }
     set { SetPropertyValue(x => x.DefaultTemplate, value); }
 }

 [ModelDefault("Tooltip", "List of numerators")]
 // The attribute is required to nested collection behave as aggregated collection
 //in UI and modification logic.
 [Aggregated]
 public IList<NumeratorCfgObject> Numerators
 {
     get { return GetCollection<NumeratorCfgObject, IModelServicesNumerator>(x => x.Numerators); }
 }

 //...
 }

In the given example, the NumeratorsCfgObject.DefaultTemplate property has the same name and type compared to the corresponding IModelServicesNumerators DefaultTemplate node of the Services Model.

A sample wrapper class for the IModelServicesNumeratorLink:

  • c#
  • c#(original)

[DomainComponent]
public class NumeratorLinkCfgObject : ServiceCfgObject<NumeratorLinkCfgObject, IModelServicesNumeratorLink>
{
  // Readonly property
  public string DisplayName
  {
    get
    {
      return GetPropertyValue<string>(x => x.DisplayName);
    }
  }
  // ModelNodesLookupPropertyEditor is used to edit the property.
  // The editor uses Application.BOModel as datasource property.
  [ModelDefault("Tooltip", "Numbering is applied for specified class")]
  [XafDisplayName("Type")]
  [EditorAlias(XafariEditorAliases.ModelNodesLookupPropertyEditor)]
  public IModelClass ModelClass
  {
    get
    {
      return GetPropertyValue<IModelClass>(x => x.ModelClass);
    }
    set
    {
      SetPropertyValue(x => x.ModelClass, value);
    }
  }
  //...
}

[DomainComponent]
 public class NumeratorLinkCfgObject : ServiceCfgObject<NumeratorLinkCfgObject, IModelServicesNumeratorLink>
 {
 // Readonly property
 public string DisplayName
 {
     get { return GetPropertyValue<string>(x => x.DisplayName); }
 }

 [ModelDefault("Tooltip", "Numbering is applied for specified class")]
 [XafDisplayName("Type")]
 // ModelNodesLookupPropertyEditor is used to edit the property.
 // The editor uses Application.BOModel as datasource property.
 [EditorAlias(XafariEditorAliases.ModelNodesLookupPropertyEditor)]
 public IModelClass ModelClass
 {
     get { return GetPropertyValue<IModelClass>(x => x.ModelClass); }
     set { SetPropertyValue(x => x.ModelClass, value); }
 }

 //...
 }