Bug or am I doing it wrong?

27 views
Skip to first unread message

michiel....@gmail.com

unread,
Apr 14, 2016, 11:07:48 AM4/14/16
to AutoMapper-users
Hi there,

I am trying to map between objects created from svcUtil classes.
For the most part it is the same structure but different namespaces.

The problem I am having is that after the Map has been executed the top level object is of the right type (target) but the nested object still is of the source type.
I've included the nested type in the mapping. 

Here is the code I use:

Setup of mapper:
  Mapper.Initialize(cfg =>
      {
        // map from Type A => Type B
        cfg.CreateMap<Service.LocatieService.GeneratedTypes.GeefLocatiesResponse, Service.LocatieService32.GeneratedTypes.GeefLocatiesResponse>();
        cfg.CreateMap<Service.LocatieService.GeneratedTypes.LocatieType, Service.LocatieService32.GeneratedTypes.LocatieType>();
      });


 // Create Type A (and add some data (all of Type A)
var typeA = new Service.LocatieService.GeneratedTypes.GeefLocatiesResponse();
typeA.Items = new[] {new Service.LocatieService.GeneratedTypes.LocatieType {LocatieID = "123"}};

//Now map to TypeB
var result = Mapper.Map<Service.LocatieService32.GeneratedTypes.GeefLocatiesResponse>(typeA);

The nested type in GeefLocatiesResponse is perhaps not really straighforward, maybe this causes the mixup?

  [GeneratedCode("svcutil", "4.6.1055.0")]
  [Serializable]
  [DebuggerStepThrough]
  [DesignerCategory("code")]
  [XmlType(AnonymousType = true, Namespace = "http://url/locatieService/v3.2/")]
  public class GeefLocatiesResponse
  {
    private object[] itemsField;

    /// <remarks />
    [XmlElement("Fout", typeof(FoutType), Order = 0)]
    [XmlElement("Locatie", typeof(LocatieType), Order = 0)]
    public object[] Items
    {
      get { return itemsField; }
      set { itemsField = value; }
    }
  }

Hope someone has an idea how to fix/workaround this.
I can send a sample application demonstrating this.

TIA!

Michiel.
Reply all
Reply to author
Forward
0 new messages