A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/MapsterMapper/Mapster/wiki/Mapping-readonly-prop below:

Mapping readonly prop · MapsterMapper/Mapster Wiki · GitHub

Mapster can map to non public setter automatically.

public class Order {
    public string Id { get; set; }
    public ICollection<OrderItem> Items { get; private set; }
}
Using UseDestinationValue attribute

You can make your type pure readonly and annotate with [UseDestinationValue].

public class Order {
    public string Id { get; set; }

    [UseDestinationValue]
    public ICollection<OrderItem> Items { get; } = new List<OrderItem>();
}

Or you can apply without annotate each type, for example, if you would like all readonly ICollection<> to use destination value.

TypeAdapterConfig.GlobalSettings.Default
    .UseDestinationValue(member => member.SetterModifier == AccessModifier.None &&
                                   member.Type.IsGenericType &&
                                   member.Type.GetGenericTypeDefinition() == typeof(ICollection<>));

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4