1

Closed

GlobalDecimalResolver doesn't run

description

In 1.0.15 beta global decimal resolver doesn't execute. Regular decimal resolver runs correctly. Global bool and int resolvers run correctly. Here's my code:

//decimal global resolver doesn't work
//GridModelMapper.Configuration.AddGlobalValueResolver<GlobalDecimalValueResolver>();

//works
GridModelMapper.CreateMap<LeadListing, LeadViewModel>()
.MapProperty(x => x.ThresholdAmount, vm => vm.Threshold).WithResolver<DecimalValueResolver>();
/////////////////////////////////////////////////////

public class DecimalValueResolver : IValueResolver
{
public object Resolve(ResultContext source)
{
    return Convert.ToDecimal(source.Value);
}
}

public class GlobalDecimalValueResolver : GlobalValueResolver<double, decimal>
{
protected override decimal ResolveCore(double source)
{
    return Convert.ToDecimal(source);
}
}
Closed Mar 19, 2012 at 10:34 PM by Luis_Fernando

comments

Luis_Fernando wrote Mar 19, 2012 at 1:43 AM

I think it's not a bug, I searched for it but found nothing wrong.

The property "LeadListing.ThresholdAmount" is of what type?

The helper looks for GlobalValueResolvers based on the source and destination types, so looking into your code, the target property must be of type "decimal", but not of the type "decimal?".

In other words, "decimal" and "decimal?" are treated as different types.

I made ​​myself clear? Is that the problem?

Noyabronok wrote Mar 19, 2012 at 2:17 PM

You're absolutely right. I added the following class to globalResolution and everything works great. Issue closed.

public class GlobalNullDecimalValueResolver : GlobalValueResolver<double, decimal?>
{
protected override decimal? ResolveCore(double source)
{
    return Convert.ToDecimal(source);
}
}