How to force Automapper to overwrite array property?
Tag : chash , By : user86493
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I am using Automapper in my project to map business entities to DTO. , I solved my problem by downgrading to version 2.0.0.
|
Overwrite Existing Mapping with Automapper
Tag : chash , By : Cube_Zombie
Date : March 29 2020, 07:55 AM
may help you . using Automapper version 5.2.0, your syntax should be as below. You should use ResolveUsing instead of MapFrom and swith-case should be within curly brackets. you dont have to use any Mapper.Initialize(). I tested this code and it works for me. I hope that it helps for you also. Cheers. Similar question asked here. see the answer from Mrchief var config = new MapperConfiguration(cfg =>
{
Mapper.CreateMap<Report, ReportViewModel>()
.ForMember(src => src.Value,
dest => dest.ResolveUsing(r => {
switch(reportingPeriod)
{
case ReportingPeriod.Daily:
return r.Day.Value;
break;
case ReportingPeriod.Weekly:
return r.Week.Value;
break;
case ReportingPeriod.Monthly:
return r.Month.Value;
break;
case default:
//None
return null;
break;
}
}));
});
var mapper = config.CreateMapper();
|
Array merge with same key's dont' overwrite
Date : March 29 2020, 07:55 AM
may help you . Values in the input array with numeric keys will be renumbered with incrementing keys starting from zero in the result array.
|
Automapper Mapping Objects of Same Type - Overwrite Bools
Tag : chash , By : meehan
Date : March 29 2020, 07:55 AM
it helps some times If you're implementing some logic on mapping, better do it on each member explicitly. But if you really want to do it via AutoMapper magic, you can add this condition: options.Condition((source, destination, member) => (member as bool?) != false);
|
Modify xls to look for any existing attribute, if present don't overwrite w/ xsi:nil="true"
Date : March 29 2020, 07:55 AM
this will help You just need to add a check for attributes in your template match too... <xsl:template match="*[not(text()) and not(@*)]">
<xsl:copy>
<xsl:attribute name="xsi:nil">true</xsl:attribute>
</xsl:copy>
</xsl:template>
<a><b>Hello</b></a>
<xsl:template match="*[not(text()) and not(*) and not(@*)]">
|