これは非常に単純な質問のように思われるので、うまくいけばこれは簡単になるでしょう。
Automapperでマップする習慣stringがあります。boolこれは単にandtoとに"Y"変換"N"しtrueますfalse。それほど単純にはなりません。
Mapper.CreateMap<string, bool>().ConvertUsing(str => str.ToUpper() == "Y");
これは、この原始的な例ではうまく機能します。
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);
ただし、代わりに:Sourceからデータを取得したいとします。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);
のすべてについてDest、mappedプロパティIsFooはtrueです。ここで何が欠けていますか?