Hi,
is it possible to have private or at least internal destination properties in DTOs?
For example:
``` C#
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.
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
}
}
For newer versions:
public class PrivateInternalProfile {
protected override Configure() {
ShouldMapField = fieldInfo => true;
ShouldMapProperty = propertyInfo => true;
CreateMap<User, UserDto>(); //etc
}
}
for even newer versions
```
public class PrivateInternalProfile : Profile {
public PrivateInternalProfile() {
ShouldMapField = fieldInfo => true;
ShouldMapProperty = propertyInfo => true;
CreateMap
}
}
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.
Most helpful comment
for even newer versions(); //etc
```
public class PrivateInternalProfile : Profile {
public PrivateInternalProfile() {
ShouldMapField = fieldInfo => true;
ShouldMapProperty = propertyInfo => true;
CreateMap
}
}