EDIT: enable TypeConverter
To set up the scene, I delete the code from the existing WCF service to be placed in the business object (BO) that WCF will reference to provide information to clients. The requirement is to force the employeeId of the Employee object to be an integer, rather than the currently used string. I use AutoMapper to map all objects between BO and WCF so that contracts are not interrupted. However, I am struggling with how to provide a back and forth mapping so that EmployeeId is an integer in BO and is still contractually serving strings through WCF.
BO
public class Employee { public int Id {get; set;} ...... }
FOS
[DataContract(Name = "Employee", Namespace="url")] public class Employee { [DataMember(Order = 1)] public string Id {get; set;} ...... }
Chart maker
Mapper.CreateMap<Employee.Entity.Employee, Employee.Service.Entity.Employee>()
PaddedStringTypeConverter Class:
public class PaddedStringTypeConverter : ITypeConverter<int, string> { public string Convert(ResolutionContext context) { var sourceValue = System.Convert.ToInt32(context.SourceValue); return sourceValue.ToString("D9"); } }
I saw that I can use Custom Type Converters in AutoMapper to change the BO from an integer to our fixed length of nine characters, so an integer value of 4610 will be equivalent to the string "000004610". However, how do I return it to an integer value.
How do you do this?
Hitek source share