-
Notifications
You must be signed in to change notification settings - Fork 331
Mapping non public members
gt4dev edited this page May 27, 2020
·
4 revisions
This will allow Mapster to set to all non-public members.
//type pair
TypeAdapterConfig<Poco, Dto>.NewConfig().EnableNonPublicMembers(true);
//global
TypeAdapterConfig.GlobalSettings.Default.EnableNonPublicMembers(true);
You can also map non-public members with AdaptMember
attribute.
public class Product
{
[AdaptMember]
private string HiddenId { get; set; }
public string Name { get; set; }
}
Map
command can map to private member by specify name of the members.
TypeAdapterConfig<TSource, TDestination>
.NewConfig()
.Map("PrivateDestName", "PrivateSrcName");
With IncludeMember
, you can select which access modifier to allow.
TypeAdapterConfig.GlobalSettings.Default
.IncludeMember((member, side) => member.AccessModifier == AccessModifier.Internal
|| member.AccessModifier == AccessModifier.ProtectedInternal);
If type doesn't contain public properties, Mapster will treat type as primitive, you must also declare type pair to ensure Mapster will apply non-public member mapping.
TypeAdapterConfig.GlobalSettings.Default.EnableNonPublicMembers(true);
TypeAdapterConfig<PrivatePoco, PrivateDto>.NewConfig();
- 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