mirror of https://github.com/abpframework/abp.git
csharpabpc-sharpframeworkblazoraspnet-coredotnet-coreaspnetcorearchitecturesaasdomain-driven-designangularmulti-tenancy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
2.3 KiB
61 lines
2.3 KiB
using System.Collections.Generic;
|
|
using Volo.Abp.AutoMapper;
|
|
using Volo.Abp.Data;
|
|
using Volo.Abp.ObjectExtending;
|
|
|
|
namespace AutoMapper;
|
|
|
|
public static class AbpAutoMapperExtensibleObjectExtensions
|
|
{
|
|
public static IMappingExpression<TSource, TDestination> MapExtraProperties<TSource, TDestination>(
|
|
this IMappingExpression<TSource, TDestination> mappingExpression,
|
|
MappingPropertyDefinitionChecks? definitionChecks = null,
|
|
string[]? ignoredProperties = null,
|
|
bool mapToRegularProperties = false)
|
|
where TDestination : IHasExtraProperties
|
|
where TSource : IHasExtraProperties
|
|
{
|
|
return mappingExpression
|
|
.ForMember(
|
|
x => x.ExtraProperties,
|
|
y => y.MapFrom(
|
|
(source, destination, extraProps) =>
|
|
{
|
|
var result = extraProps.IsNullOrEmpty()
|
|
? new Dictionary<string, object?>()
|
|
: new Dictionary<string, object?>(extraProps);
|
|
|
|
if (source.ExtraProperties == null || destination.ExtraProperties == null)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
ExtensibleObjectMapper
|
|
.MapExtraPropertiesTo<TSource, TDestination>(
|
|
source.ExtraProperties,
|
|
result,
|
|
definitionChecks,
|
|
ignoredProperties
|
|
);
|
|
|
|
return result;
|
|
})
|
|
)
|
|
.ForSourceMember(x => x.ExtraProperties, x => x.DoNotValidate())
|
|
.AfterMap((source, destination, context) =>
|
|
{
|
|
if (mapToRegularProperties)
|
|
{
|
|
destination.SetExtraPropertiesToRegularProperties();
|
|
}
|
|
});
|
|
}
|
|
|
|
public static IMappingExpression<TSource, TDestination> IgnoreExtraProperties<TSource, TDestination>(
|
|
this IMappingExpression<TSource, TDestination> mappingExpression)
|
|
where TDestination : IHasExtraProperties
|
|
where TSource : IHasExtraProperties
|
|
{
|
|
return mappingExpression.Ignore(x => x.ExtraProperties);
|
|
}
|
|
}
|
|
|