Creating a DTO

Let's see this with an example. In this case we will create a mapper for a Button model.

First we need a DTO. A DTO is Plain Old C# Object (POCO). In this example our DTO will be like the following:

A DTO class must use a DataTransfer attribute from Mobilize.WebMap.Common.Attributes.

    [DataTransfer("btn")]
    public class Button
    {
        public string Text { get; set; }
        public string Name { get; set; }
    }

Or alternatively must implement the IDataTransfer interface.

public class Button : IDataTransfer
{
public string Text { get; set; }
public string Id { get; set; }
public string MapperId { get; set; }
}

Follow these guidelines when creating your DTOs:

  • 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

Last updated