我想使用AutoMapper将两个对象链接起来。它运行良好,但现在我想将小数点的项目格式化为2位小数。Automapper将小数设置为全部为2位小数
这就是我所拥有的。我究竟做错了什么?
Mapper.CreateMap<Object1, Object2>()
.ForMember(x => typeof(decimal), x => x.AddFormatter<RoundDecimalTwo>());
这里是RoundDecimalTwo格式化
public class RoundDecimalTwo : IValueFormatter
{
public string FormatValue(ResolutionContext context)
{
return Math.Round((decimal)context.SourceValue,2).ToString();
}
}
而且你的十进制性能确实只是小数(而不是可为空)? –
2011-02-24 22:51:26