-
Notifications
You must be signed in to change notification settings - Fork 334
Mapping readonly prop
chaowlert edited this page Feb 2, 2020
·
1 revision
Mapster can map to non public setter automatically.
public class Order {
public string Id { get; set; }
public ICollection<OrderItem> Items { get; private set; }
}
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<>));
- Configuration
- Config inheritance
- Config instance
- Config location
- Config validation & compilation
- Config for nested mapping
- Custom member matching logic
- Constructor mapping
- Before & after mapping
- Setting values
- Shallow & merge mapping
- Recursive & object references
- Custom conversion logic
- Inheritance