2011-11-17 1 views
13

ITypeConverter 인터페이스가 Convert 메서드의 "TDestination Convert (TSource source)"대신 "TDestination Convert (ResolutionContext context)"로 변경되었습니다. 내 매퍼 같은 새로운 매퍼AutoMapper 2.0에서 ITypeConverter 인터페이스가 변경되었습니다.

'BusinessFacade.Mappers.DecimalToNullableInt' does not implement interface member 'AutoMapper.ITypeConverter.Convert(AutoMapper.ResolutionContext)'

모든 좋은 전체 샘플 : 내 코드에서

http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters

는, 지금은이 오류가? 나는 ITypeConverter 인터페이스는 "TDestination이 변경되었습니다

public class DecimalToNullableInt : ITypeConverter<decimal, int?> 
    { 
     public int? Convert(decimal source) 
     { 
      if (source == 0) 
       return null; 
      return (int)source; 
     } 
    } 

UPDATE 내 매퍼

... 내 프로젝트에 코드 (또는 최소 코드)을 변경하지 않으 Convert 메서드의 경우 "TDestination Convert (TSource source)"대신 "Convert (ResolutionContext context)"를 사용합니다.

설명서의 유효 기간이 만료되었습니다. 같이 기본 TypeConverter 편의 클래스 인 ITypeConverter가 있습니다. TypeConverter는 ResolutionContext를 숨기고 ITypeConverter는이를 노출합니다.

http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters

https://github.com/AutoMapper/AutoMapper/wiki/Custom-type-converters

http://groups.google.com/group/automapper-users/browse_thread/thread/6c523b95932f4747

답변

15

당신은 ResolutionContext.SourceValue 속성에서 소수를 잡아해야합니다 :

public int? Convert(ResolutionContext context) 
    { 
     var d = (decimal)context.SourceValue; 
     if (d == 0) 
     { 
      return null; 
     } 
     return (int) d; 
    }