Skip to content

Dictionary to Constructor Mapping #4095

@innominate227

Description

@innominate227

Source/destination types

public class Foo
{
    public Foo(int baz, int bar)
    {
        Baz = baz;
        Bar = bar;
    }

    public int Baz { get; }
    public int Bar { get; }
}

Mapping configuration

var configuration = new MapperConfiguration(cfg => { });
var mapper = configuration.CreateMapper();

Version: x.y.z

12.0.0

Expected behavior

an instance of Foo is created with Baz set to 3 and Bar set to 6.

Actual behavior

Exception thorwn
Test.Foo needs to have a constructor with 0 args or only optional args. Validate your configuration for details.

Steps to reproduce

var configuration = new MapperConfiguration(cfg => { });            
var mapper = configuration.CreateMapper();
var dict = new Dictionary<string, object>
{
    {"baz",3},
    {"bar",6},
};            
var result = mapper.Map<Foo>(dict);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions