类具有自动IEnumerable属性的Class时自动映射器

时间:2018-08-30 10:45:44

标签: c# automapper

我上了一堂课

public class Location {

private readonly List<Location> nearByLocations = new List<string>();

public Location(string name, LocationProperties locationProperties)
    {
        this.Id = id;
        this.Name = name;
        this.LocationProperties = locationProperties;
    }

public string Name {get;}

public LocationProperties LocationProperties { get; }

public IReadOnlyList<Location> GetNearByLocation => this.nearByLocations;

public void AddNearByLocations(IEnumerable<Location> nearByLocationList) => this.nearByLocations.AddRange(nearByLocationList);

}

MyDto将具有NearByLocations作为逗号分隔的字符串,仅包含位置名称。 有没有一种方法可以使用automapper映射附近的位置。

像这样的事情有可能吗?一旦将字符串拆分为Dto,就可以从Dto的列表中为所有字符串构造Location对象并添加它。

0 个答案:

没有答案