3

I am using Emit Mapper to copy fields from InternalClass to ExternalClass.

public class InternalClass {
   public int? Id { get; set; }
   public DateTime? RecordDate {get; set;}
}

public class ExternalClass {
   public int Id { get; set; }
   public DateTime RecordDate {get; set;}
}

I use the following code to convert a List to a List.

ObjectMapperManager.DefaultInstance.GetMapper<InternalClass, ExternalClass>(
new DefaultMapConfig()).Map(list);  // list = List<InternalClass>

But it gives me "Nullable object must have a value". I've also tried overriding the non-nullable properties:

ObjectMapperManager.DefaultInstance
.GetMapper<List<InternalClass>, List<ExternalClass>>(
   new DefaultMapConfig()
   .NullSubstitution<int?, int>(delegate { return default(int); })
   .NullSubstitution<DateTime?, DateTime>(delegate { return default(DateTime); }) 
).Map(source);

I also tried making the types in both classes nullable but no luck. Any other ideas?

Adam
  • 4,590
  • 10
  • 51
  • 84

0 Answers0