Skip to content

Server DTO

DeclanBuckley edited this page Jan 25, 2021 · 11 revisions

Home / Developer / Server Tier / DTO

DTO (Data Transfer Object) definition and example.

Summary.

DTOs are used as a simple Data Transfer Object in order to hold an object corresponding to the Json parameters in the API call. Typically there is one DTO for each parameter set, however it is useful in some cases to re-use DTOs if the parameters of various API calls are similar. Where appropriate, DTO properties may be decorated with custom attributes. The constructor is used in order to populate the DTO properties with the Request parameters.

Example of a DTO.

internal class Language_DTO_Create
{
    [LowerCase]
    public string LngIsoCode { get; set; }
    public string LngIsoName { get; set; }

    public Language_DTO_Create(dynamic parameters)
    {
        if (parameters.LngIsoCode != null)
            this.LngIsoCode = parameters.LngIsoCode;
        if (parameters.LngIsoName != null)
            this.LngIsoName = parameters.LngIsoName;
    }
}

In this case, the DTO has two properties and the constructor is used to populate the properties from the parameters. Also note that the LngIsoCode property takes the [LowerCase] custom attribute.

Clone this wiki locally