How to create a new Control
Suppose you need to implement the following user story:
As a user, I want to create a CustomLabel that not only has a property Text of the Label but also a AnotherText property that stores another text. When someone modifies the value of AnotherText, it should trigger an event indicating that this property has been changed.
In order to implement this user story, you will have to do the following things:
    1.
    An Observable Class
    2.
    A Data Transfer Object
    3.
    A Mapper
    4.
    Register the mapper in the RegistrationClass

1. Creating CustomLabel Observable Class

Please follow the following steps:
    1.
    Create the class
    2.
    Add ObservableAttribute
    3.
    Add the required properties and add InterceptedAttribute to the properties that you want them to be persisted throughout the WebMAP's life cycle.
    1
    [Observable]
    2
    public class CustomLabel : Label
    3
    {
    4
    [Intercepted]
    5
    public string AnotherTextInternal { get; set;}
    6
    7
    public string AnotherText
    8
    {
    9
    get
    10
    {
    11
    return this.AnotherTextInternal;
    12
    }
    13
    set
    14
    {
    15
    this.AnotherTextInternal = value;
    16
    this.AnotherTextChanged(EventArgs.Empty);
    17
    }
    18
    }
    19
    20
    [Intercepted]
    21
    public EventHandler AnotherTextChanged { get; set; }
    22
    23
    protected virtual void OnAnotherTextChanged(EventArgs e)
    24
    {
    25
    this.AnotherTextChanged?.Invoke(this,EventArgs.Empty);
    26
    }
    27
    }
    Copied!

Observations when adding ObservableAttribute

When you add this attribute, it means the the class will be an observable class. So please take into account the following observations:
    An observable class can have private, internal or public modifier.
    An observable class can be sealed.
    An observable class can be abstract.
    When you add Observable attribute to a class. All classes that inherits from that class will be observables. Even if attribute is not present in one of those classes.

Observations when adding InterceptedAttribute

When you add this attribute, it means the the property will be intercepted, this means that this property will live under the WebMAP's life cycle, its value will be persisted throughout the requests. So please take into account the following observations:
    Properties can be virtual or non virtual.
    Properties can be public, private, internal or protected.
    Properties must be auto implemented
    Property type can be any value type or string, or any type marked as an observable.
    Properties can be static

2. Creating CustomLabel Data Transfer Object

Please follow the following steps:
    1.
    Create a Data Transfer Object class
    2.
    Add DataTransferAttribute to the class
    3.
    Add the properties that you want to synchronize between frontend and backend CSharp [DataTransfer("cstmlbl")] public class CustomLabel { public string Text { get; set; } public string AnotherText { get; set; } }

Observations

    classes should not inherit from any other classes
    use nullable types for value types. For example int? instead of int
    the name used on the DataTransfer attribute should be
      unique
      as short as possible
      it should start with a lowercase consonant
      it should not use vowels
      if it is made up of several words the next word should have just its first letter in uppercase

3. Creating CustomLabel Mapper

Please follow the following steps:
    1.
    Create the mapper class
    2.
    Implement IMapper interface, in which the first type parameter of this generic interface should be the model. The second parameter of generic interface is the DTO class.
    3.
    Implement the methods of IMapper
    1
    public class CustomLabelMapper : IMapper
    2
    {
    3
    public void Configure(MapperInformation config)
    4
    {
    5
    // There are not References to report
    6
    }
    7
    8
    public object Map(IObservable observable)
    9
    {
    10
    var source = observable as CustomLabel;
    11
    12
    var result = new DTO.CustomLabel()
    13
    {
    14
    Text = source.GetChange( x=> x.TextInternal),
    15
    AnotherText = source.GetChange( x=> x.AnotherTextInternal)
    16
    };
    17
    return result;
    18
    }
    19
    20
    public void ApplyChanges(IObservable observable IDataTransfer dto)
    21
    {
    22
    var target = observable as CustomLabel;
    23
    var source = dto as DTO.Label;
    24
    if (source.Text != null && source.Text !=target.Text)
    25
    {
    26
    target.Text = source.Text;
    27
    }
    28
    if (source.AnotherText != null &&source.AnotherText != target.AnotherText)
    29
    {
    30
    target.AnotherText = source.AnotherText;
    31
    }
    32
    }
    Copied!
    Observations
    4.
    Map: this method is called to create a DTO instance and populate from the model. If you do not want to send anything to the client you can return null
    5.
    ApplyChanges: this method is called to sync back data from the client. In this method you can take data sent from the client and apply those changes to the model on the backend. E.g. If there were a change of AnotherText from client side, it will update the value and trigger the AnotherTextChanged event.
    6.
    Configure: this method is called to setup which data elements from the model must be considered as references.
    7.
    The extension method GetChange must be used. This returns null when the property doesn't been modified during the request, otherwise, it returns the value of the modified property.

4. Register the mapper

This final step is simply going to the Registration class (situated under DTO project) and add the following line to the RegisterMapper method:
1
public class Registrations : IRegistration
2
{
3
public void RegisterMappers(IMapperCatalog catalog, ILogger logger)
4
{
5
...
6
...
7
catalog.AddMapper(new CustomLabelMapper());
8
}
9
}
Copied!