Skip to content

Mapping nullable Enum to custom object #640

@WahidBitar

Description

@WahidBitar

for now I can have something like the following to register mapping for all enums in the system

config.NewConfig<Enum, KeyValueData>()
            .MapWith(s => new KeyValueData(s, Enums.ResourceManager));

However, it's not possible to have the same cofig for a nullable Enum.

The following config is not working:

config.NewConfig<Enum?, KeyValueData?>()
            .MapWith(s => s == null ? null : new KeyValueData(s.ToString(), Enums.ResourceManager));

I'll get the following Exception

Error while compiling
source=Tests.FirstClass
destination=Tests.SecondClass
type=Map
-> InnerException:
Error while compiling
source=System.Nullable`1[Model.IdentityType]
destination=Model.KeyValueData
type=Map
--> InnerException:
No default constructor for type 'KeyValueData', please use 'ConstructUsing' or 'MapWith'

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