This seems like a very simple question, so hopefully this will be easy.
I have a custom string
to bool
map in Automapper that simply converts "Y"
and "N"
to true
and false
. It doesn't get much simpler:
Mapper.CreateMap<string, bool>().ConvertUsing(str => str.ToUpper() == "Y");
This works fine in this primitive example:
public class Source
{
public string IsFoo { get; set; }
public string Bar { get; set; }
public string Quux { get; set; }
}
public class Dest
{
public bool IsFoo { get; set; }
public string Bar { get; set; }
public int Quux { get; set; }
}
// ...
Mapper.CreateMap<string, bool>().ConvertUsing(str => str.ToUpper() == "Y");
Mapper.CreateMap<Source, Dest>();
Mapper.AssertConfigurationIsValid();
Source s = new Source { IsFoo = "Y", Bar = "Hello World!", Quux = "1" };
Source s2 = new Source { IsFoo = "N", Bar = "Hello Again!", Quux = "2" };
Dest d = Mapper.Map<Source, Dest>(s);
Dest d2 = Mapper.Map<Source, Dest>(s2);
However, let's say instead I want to take the Source
data from a DataReader
:
Mapper.CreateMap<string, bool>().ConvertUsing(str => str.ToUpper() == "Y");
Mapper.CreateMap<IDataReader, Dest>();
Mapper.AssertConfigurationIsValid();
DataReader reader = GetSourceData();
List<Dest> mapped = Mapper.Map<IDataReader, List<Dest>>(reader);
For every Dest
in mapped
, the IsFoo
property is true
. What am I missing here?