0

I have three classes

public class A
{
    public string Value1 { get; set; }
    public string Value2 { get; set; }
}

public class B
{
    public int Value1 { get; set; }
    public string Value2 { get; set; }
}

public class C
{
    public int Value1 { get; set; }
    public int Value2 { get; set; }
}

I want to be able to Map

A->B

B->C

A->C

so I have two configs

public void AddMappings()
{
    TypeAdapterConfig<A,B>
      .ForType()
      .Map(dest => dest.Value1, src => ConvertToInt(src.Value1));
    TypeAdapterConfig<B,C>
      .ForType()
      .Map(dest => dest.Value2, src => ConvertToInt(src.Value2));
}

Is there a way to configure mapster so it knows that it can use A->B + B->C to map A->C? This would help because otherwise I need to make another TypeAdapterConfig<A, C> where I Map both Value1 and Value2.

Sidereus
  • 200
  • 3
  • 13
  • _"However this does not seem to work per default."_ - why do you think it should? What about `A -> B -> C -> D` ? What if there are couple hundreds of types with defined mappings in the system? What if in `A -> B -> C` `B` misses some fields present both in `A` and `C`? – Guru Stron Feb 01 '23 at 13:52
  • There is no reason to think that (a->b) and (b->c) are additive. And there is no graph build in the back ground to map everything related and their links. Where you may have multiple path leading from A to C, some lossless, some with more step, and loops. – Drag and Drop Feb 01 '23 at 14:00
  • @Guru Stron I didn't say that it should. I simply pointed out that it doesn't work without any additional configuration. But if I can tell mapster somehow that it can get from A->C by doing A->B and then B->C it should work to use a.Adapt right? The question is if and how I can configure this? – Sidereus Feb 01 '23 at 15:15

0 Answers0