I want to map between two classes:
public class A {
public IEnumerable<C> someList
}
and
public class B {
public RepeatedField<D> someList
}
where RepeatedField is a class from Google.Protobuf.Collections that handles gRPC data.
EDIT: As it turns out, the way that gRPC creates classes via its prototype is not exactly like creating a class like B. See my answer.
I create an Automapper MappingConfiguration like this
return new MapperConfiguration(cfg =>
{
cfg.CreateMap<C, D>().ReverseMap();
cfg.CreateMap<A, B>().ReverseMap();
});
and then it gets registered via ASP.NET Startup class.
If I do something like this in another class
A instanceA; // assume A's list has values inside
var listofD = this.mapper.Map<List<D>>(A.someList)
it correctly returns a list with values inside. However:
A instanceA; // assume A's list has values inside
B instanceB = this.mapper.Map<B>(A);
returns an instance of B, but the list inside of instanceB is empty. How do I fix this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…