Does anyone support this project ?

Jun 28, 2012 at 8:43 PM

 ?

Developer
Jun 28, 2012 at 9:18 PM

yes. what kind of support do you need?

Jun 29, 2012 at 2:09 PM
Edited Jun 29, 2012 at 2:11 PM

Hello. Sorry for my previous question, I thought that the project isn`t supported.

I have a question about mapping properties without public setter. For example:

public class ActiveAccount
    {
        public Int32? Id { get; protected set; }
        
        public String Name { get; set; }        
    }

After mapping the 'Id' property is always 0 (zero). In this case I should make setter public, but really I don`t want to do it. Is there any solution to avoid this behaviour ?

Developer
Jun 30, 2012 at 11:42 AM

It  is not so easy because of emit and IL that doesnt allow call non-public methods.

If you need this only for specific class you can use ConvertUsing method

public class AProtected
{
     public AProtected()
     {
        ProtectedFld1 = 1;
     }

     public int? ProtectedFld1 { get; protected set; }
}

public class BProtected
{
    public BProtected() { } 

    public BProtected(int? p) { ProtectedFld1 = p; }

    public int? ProtectedFld1 { get; protected set; }
}


var mapper = Context.objMan.GetMapper<AProtected, BProtected>(
                new DefaultMapConfig().
                    ConvertUsing<AProtected, BProtected>(ap => new BProtected(ap.ProtectedFld1)));
            mapper.Map(a);
but its rather ugly hack for your situation