Is it possible to set all string properties that are null in my source object to some default value within my destination object using AutoMapper?
For example, let's say I had the following two class definitions:
public class UniversalForm
{
public string LastName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string FaxNumber { get; set; }
...
}
public class UniversalFormDto
{
public string LastName { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string FaxNumber { get; set; }
...
}
Now, MiddleName and FaxNumber are properties that are likely to be null in the UniversalForm class. So what I would like to be able to do is if FaxNumber or MiddleName are null then in UniversalFormDto object I would like for the value of the corresponding properties to be set to "N/A".
I know this can be accomplished by creating a mapping for each individual member, but I would like to avoid that if at all possible.
I'm looking for a way to define a default value for all my string properties to be used when the corresponding property on my source object (UniversalForm) is null.