dj-raphael / T4Mapping

Generate mapping methods DO models to DTO with t4 template
MIT License
13 stars 1 forks source link

Object initializer instead of properties initialization #2

Closed KvanTTT closed 9 years ago

KvanTTT commented 9 years ago

I mean use the following code:

var itemDto = new DataTransferObject.UserDto
{
    UserId = item.UserId,
    Username = item.Login,
    Created = item.Created,
    Email = item.Email
};

instead of:

var itemDto = new DataTransferObject.UserDto ();
    itemDto.UserId = item.UserId;
    itemDto.Username = item.Login;
    itemDto.Created = item.Created;
    itemDto.Email = item.Email;

It can be additional setting in MapHelper.tt

dj-raphael commented 9 years ago

Initially it was, but when we needed map to ObservableRangeCollenction it had rewritten. See MappingExtension.g.cs:L67 But this generated code, what difference would it look like? Object initializers are just syntactic sugar, in your compiled assembly IL they translate into separate statements, check it on ILSpy.

KvanTTT commented 9 years ago

Is it possible to map ObservableRangeCollenction by usual way and other objects by object initializer? But you are right: it is not important feature.

dj-raphael commented 9 years ago

ObservableRangeCollenction is readonly in each ViewModels in our projects.