Auto Mapper convert from string to Int
The problem you may face is when it is unable to parse the string, one option would be to use a ResolveUsing:
Mapper.CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.intphoneno, opts => opts.ResolveUsing(src =>
double.TryParse(src.strphoneno, out var phoneNo) ? phoneNo : default(double)));
Mapper.CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.IntphoneNo,
opt => opt.MapFrom(src => int.Parse(src.Stringphoneno)));
Here is some sample working code using the map described
class SourceClass
{
public string Stringphoneno { get; set; }
}
class DestinationClass
{
public int IntphoneNo { get; set; }
}
var source = new SourceClass {Stringphoneno = "8675309"};
var destination = Mapper.Map<SourceClass, DestinationClass>(source);
Console.WriteLine(destination.IntphoneNo); //8675309