title: Auto Mapper convert from string to Int
body: <p>I am creating a simple MVC4 application</p>
  
  <p>I have a automapper </p>
  
  <pre><code> Mapper.CreateMap&lt;SourceClass, DestinationClass&gt;()
        .ForMember(dest =&gt; dest.IntphoneNo, 
                    opt =&gt; opt.MapFrom(src =&gt; src.Stringphoneno));
  </code></pre>
  
  <p><strong>IntphoneNo</strong> is of DataType <strong>int</strong> ( IntphoneNo is an variable of my class <code>Person</code>)
  Source attribute <strong>Stringphoneno</strong> is  of Datatype <strong>string</strong>.</p>
  
  <p>When i am mapping , i am getting follwoing error.</p>
  
  <blockquote>
    <p>An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code</p>
  </blockquote>
  
  <p>But when i am changing the Dataype of <strong>IntphoneNo</strong>  from <strong>int</strong> to <strong>string</strong>  then my program is running successfully.</p>
  
  <p>Unfortunately i cant change the Datatype inmy model</p>
  
  <p>Is theer any way to change Datatupe in mapping ..
  Something like below </p>
  
  <pre><code>.ForMember(dest =&gt; dest.IntphoneNo, 
                    opt =&gt; opt.MapFrom(src =&gt; src.Int32(Stringphoneno));
  </code></pre>
  
  <p>After some research  I came one step futher ..<br>
  If my StringPhoneNo is = 123456<br>
  then follwoing code is working. I dont need to parse it to string  </p>
  
  <pre><code>Mapper.CreateMap&lt;SourceClass, DestinationClass&gt;()
        .ForMember(dest =&gt; dest.IntphoneNo, 
                    opt =&gt; opt.MapFrom(src =&gt; src.Stringphoneno));
  </code></pre>
  
  <p>but when my StringPhoneNo is = 12 3456  ( there is a <strong>space after 12</strong>) then  my code is not working.
  Is there any way to trim spaces in Stringphoneno (<strong>Stringphoneno</strong> i am geting from webservice)   in automapper.</p>
  
  <p>Something like below..</p>
  
  <pre><code>Mapper.CreateMap&lt;SourceClass, DestinationClass&gt;()
        .ForMember(dest =&gt; dest.IntphoneNo, 
                    opt =&gt; opt.MapFrom(src =&gt; src.Trim(Stringphoneno))); 
  </code></pre>