我上了一堂课
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对象并添加它。