0
votes

I have UserType object where Name properties values are UserId, LoginName, Email, ...etc of class Attribute. I need mapping UserType object to User object and reverse mapping from User to UserType . I used AutoMapper library, but I can't implement mapping.

public class UserType
{
    public string UserName { get; set; }
    public Attribute[] Attribute { get; set; }
}

User attributes class:

public class Attribute
{
    public string Name { get; set; }
    public string[] Value { get; set; }
}

Attribute example: Attribute attribute = new Attribute { Name = "LoginName ", Value = new []{"LoginName"} }

My User class:

public class User
{       
    public long UserId { get; set; }
    public string LoginName { get; set; }
    public string Email { get; set; }
    public string LastName { get; set; }
    public string FirstName { get; set; }
    public string MiddleName { get; set; }   
}
1

1 Answers

0
votes

Use reflection to find public property in User class based on Attribute.Name in UserType. Use SetValue on PropertyInfo to set value from UserType to User.

If you will be able to do it with Automapper in more natural way, let mi know.