AutoMapper: What is the difference between MapFrom and ResolveUsing?

后端 未结 5 1894
执笔经年
执笔经年 2020-11-30 07:00

Ignoring the ResolveUsing overloads that take an IValueResolver, and looking only at these 2 methods:

v         


        
5条回答
  •  悲哀的现实
    2020-11-30 07:58

    According to the source code, ResolveUsing is more complicated. The source value can be any object; therefore, you can use any value you want to fill the destination member, such as int or bool that you get by "Resolving" the given object. However, MapFrom only uses member to map from.

    /// 
    /// Resolve destination member using a custom value resolver callback. Used instead of MapFrom when not simply redirecting a source member
    /// This method cannot be used in conjunction with LINQ query projection
    /// 
    /// Callback function to resolve against source type
    void ResolveUsing(Func resolver);
    
    /// 
    /// Specify the source member to map from. Can only reference a member on the  type
    /// This method can be used in mapping to LINQ query projections, while ResolveUsing cannot.
    /// Any null reference exceptions in this expression will be ignored (similar to flattening behavior)
    /// 
    /// Member type of the source member to use
    /// Expression referencing the source member to map against
    void MapFrom(Expression> sourceMember);
    

提交回复
热议问题