Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Private/internal destination properties #600

Closed
zolakt opened this issue Oct 6, 2014 · 4 comments
Closed

Private/internal destination properties #600

zolakt opened this issue Oct 6, 2014 · 4 comments

Comments

@zolakt
Copy link

zolakt commented Oct 6, 2014

Hi,
is it possible to have private or at least internal destination properties in DTOs?

For example:

public class Company{
    public int ID {get;set;}
}

public class CompanyDTO{
    public int ID {get;set;}
}

public class User {
    public int ID {get;set;}
    public Company Company {get;set;}
}

public class UserDTO{
    public int ID {get;set;}
    internal CompanyDTO Company{get;set;}
    public int? CompanyID{
        get { return (this.Company != null) ? this.Company.ID : (int?)null;
    }
}

Currently it only works if I set the CompanyDTO property to public.
Mapping is done in the same assembly.

I'm using this approach because of NHibernate and lazy loading. I have a custom resolver which ignores uninitialized objects and doesn't trigger lazy load on them.

@jbogard
Copy link
Member

jbogard commented Nov 26, 2014

Yes, you can. In your base Profile, set the BindingFlags to something else before creating your maps:

public class PrivateInternalProfile {
    protected override Configure() {
        BindingFlags = BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic;
        CreateMap<User, UserDto>(); //etc
    }
}

@jbogard jbogard closed this as completed Nov 26, 2014
@chrisxue815
Copy link

For newer versions:

public class PrivateInternalProfile {
    protected override Configure() {
        ShouldMapField = fieldInfo => true;
        ShouldMapProperty = propertyInfo => true;
        CreateMap<User, UserDto>(); //etc
    }
}

@bogusfocused
Copy link

for even newer versions

public class PrivateInternalProfile : Profile {
    public PrivateInternalProfile() {
        ShouldMapField = fieldInfo => true;
        ShouldMapProperty = propertyInfo => true;
        CreateMap<User, UserDto>(); //etc
    }
}

@lock
Copy link

lock bot commented May 6, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants