Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Automapper map from a Dictionary of properties to a flat destination?

Tags:

automapper

Source contains a property bag in a Dictionary. Can Automapper map the entries in the Dictionary to individual properties of the Destination based upon matching the dictionary keys with the names of the properties on the destination type?

Example:

public class Destination
{
    public int ProdNumber;
    public string Title;
}

public class Source
{
    public Dictionary<string, object> values = new Dictionary<string, object>();
}

where the values Dictionary will have two entries, one with a key of "ProdNumber" and one with a key value of "Title". There will likely be entries in the dictionary that have keys that don't match any property in the Destination and they should be ignored. There will be multiple properties of each primitive data type (int, string, etc) - so I presume I can't use a simple set of TypeConverters.

Any suggestions? Thanks, Chris

like image 775
Chris Avatar asked Jan 12 '11 19:01

Chris


People also ask

How does AutoMapper work internally?

How AutoMapper works? AutoMapper internally uses a great concept of programming called Reflection. Reflection in C# is used to retrieve metadata on types at runtime. With the help of Reflection, we can dynamically get a type of existing objects and invoke its methods or access its fields and properties.

How do I ignore property in AutoMapper?

So, the AutoMapper Ignore() method is used when you want to completely ignore the property in the mapping. The ignored property could be in either the source or the destination object.


1 Answers

Unfortunately it is not possible at the moment, but it is planned for the next version. Read this thread as it discusses the plans and a work around.

like image 96
Dale Ragan Avatar answered Sep 21 '22 11:09

Dale Ragan