You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally posted by akordowski March 24, 2024
Hi everyone!
I am currently struggling with the mapping of a readonly ICollection property. I followed the instructions but I can't make it work. The readonly collection is not populated with the mapped content. What am I making wrong? Have anyone an idea how I can make it work?
Here the code:
Programm.cs
var config = TypeAdapterConfig.GlobalSettings;
config.Scan(typeof(ChannelMapping).Assembly);
config.Default.UseDestinationValue(m => m.SetterModifier == AccessModifier.None &&
m.Type.IsGenericType &&
m.Type.GetGenericTypeDefinition() == typeof(ICollection<>));
var channelSrc = new MapsterTest.Objects.Source.Channel
{
ChannelId = "123",
Thumbnails = new MapsterTest.Objects.Source.ThumbnailDetails
{
Default = new MapsterTest.Objects.Source.Thumbnail
{
Url = "https://www.youtube.com/default.jpg"
},
Medium = new MapsterTest.Objects.Source.Thumbnail
{
Url = "https://www.youtube.com/medium.jpg"
},
High = new MapsterTest.Objects.Source.Thumbnail
{
Url = "https://www.youtube.com/high.jpg"
}
}
};
// Thumbnails are mapped correctly to a collection
var thumbnailsDest = channelSrc.Thumbnails.Adapt<ICollection<MapsterTest.Objects.Destination.Thumbnail>>().ToList();
// channelDest.Thumbnails collection is empty
var channelDest = channelSrc.Adapt<MapsterTest.Objects.Destination.Channel>();
Discussed in #688
Originally posted by akordowski March 24, 2024
Hi everyone!
I am currently struggling with the mapping of a readonly ICollection property. I followed the instructions but I can't make it work. The readonly collection is not populated with the mapped content. What am I making wrong? Have anyone an idea how I can make it work?
Here the code:
Programm.cs
ThumbnailMapping.cs
Channel.cs (Destination)
Thumbnail.cs (Destination)
Channel.cs (Source)
ThumbnailDetails.cs (Source)
Thumbnail.cs (Source)
The text was updated successfully, but these errors were encountered: