AutoMapper - anti-aliasing types with very long property names

I'm working on a project that needs to consume an ebay webservice and I'm using their eBay.NET SDK. And since there are a lot of mappings going on between their model and my model, I thought I'd finally give AutoMapper a try.

So this is the ebay API im working with (small part):

public class SellingManagerProductType {

    SellingManagerProductDetailsType SellingManagerProductDetails { get; set; }

    SellingManagerProductInventoryStatusType SellingManagerProductInventoryStatus { get; set; }

   // other properties 
}

public class SellingManagerProductDetailsType {
    long ProductID { get; set; }
    string ProductName { get; set; }
    string CustomLabel { get; set; }
    // other properties... 
}

public class SellingManagerProductInventoryStatusType {
    int QuantityActive { get; set; }
    int QuantityScheduled { get; set; }
    int QuantitySold { get; set; }
    int QuantityUnsold { get; set; }
    // other properties.. 
} 

      

In this case my model is a very simple POCO, it just flattens the SellingManagerProductType that I am using in CRUD operations.

public class EbaySellingManagerProduct  {
    long ProductID { get; set; }
    string ProductName { get; set; }
    string CustomLabel { get; set; }
    int QuantityActive { get; set; }
    int QuantityScheduled { get; set; }
    int QuantitySold { get; set; }
    int QuantityUnsold { get; set; }
}

      

Now I would like to flatten the SellingManagerProductType for my EbaySellingManagerProduct using AutoMapper, but if I understood the AutoMapper default convention correctly, I would name my properties as follows:

long SellingManagerProductDetailsTypeProductID { get; set; }
string SellingManagerProductDetailsTypeProductName { get; set; }
string SellingManagerProductDetailsTypeCustomLabel { get; set; }
int SellingManagerProductInventoryStatusTypeQuantityActive { get;set;}
etc...

      

which is very painful to observe and work with ... And there are many more of these types of comparisons.

My first thought was what I could use .ForMember

for these properties, but I would end up displaying many and many of them and would hardly benefit from using this tool. Are there any other options for me to avoid these long property names?

I am very new to AutoMapper and any guidance would be greatly appreciated. Thank.

+3


source to share


1 answer


It looks like the class names are long and not necessary.

In this case, you can alias class names with operators using

.

Example:



using Details = My.Namespace.SellingManagerProductDetailsType;

After that you can refer to the class SellingManagerProductDetailsType

at Details

.

This might make things shorter for you, but it would require a group of cookie cutters using

at the top of each of your code files.

0


source







All Articles