2015-09-11 56 views
0
 
Mapper.CreateMap<WorkItemSummary, WorkItemSummaryDto>() 
       .ForMember(dto => dto.ProductDisplayName, opt => opt.MapFrom(src => src.Product.DisplayName)) 
       .ForMember(dto => dto.TeamId, opt => opt.MapFrom(src => src.Product.Team.TeamId)) 
       .ForMember(dto => dto.TeamName, opt => opt.MapFrom(src => src.Product.Team.TeamName)) 
       .ForMember(dto => dto.RRConsolidated, opt => opt.ResolveUsing<WIConsolidateResolveReasonResolver>()) 
       .ForMember(dto => dto.NewBugsQuery, opt => opt.ResolveUsing<WIQueryNewBugsResolver>()) 
       .ForMember(dto => dto.ResolvedBugsQuery, opt => opt.ResolveUsing<WIQueryResolvedResolver>()) 
       .ForMember(dto => dto.ClosedBugsQuery, opt => opt.ResolveUsing<WIQueryClosedResolver>()) 
       .ForMember(dto => dto.BacklogQuery, opt => opt.ResolveUsing<WIQueryBacklogResolver>()) 
       .ForMember(dto => dto.ResolvedReasonFixQuery, opt => opt.ResolveUsing<WIQueryResolvedReasonFixResolver>()); 


--- Adding One Resolver Code and mostly all resolvers are doing same Job but pulling different content from Xml Nodes 

    public class WIQueryNewBugsResolver: ValueResolver<WorkItemSummary, string> 
    { 
     protected override string ResolveCore(WorkItemSummary source) 
     { 

     XmlDocument xmlDoc = new XmlDocument(); 
     xmlDoc.Load(System.IO.Path.Combine(AppDomain.CurrentDomain.RelativeSearchPath, "WIsQuery.xml")); 

     .... 

     } 
    } 

我有多個解析器完成幾乎相同的工作來讀取一些xmls並獲取數據。考慮在一個解析器下合併所有這些呼叫。 ex:WIConsolidateResolveReasonResolver,WIQueryResolvedReasonFixResolver,WIQueryBacklogResolverAutomapper - 使用1解析器映射多個屬性

在這方面,我可以調用一次解析器,並在一次調用中獲得所有其他屬性。

是否有適當ForMember

感謝

+0

可以請您分享完整的代碼。 –

+0

剛剛添加了一個解析器,但我這裏關心的是性能....看看是否有任何方法在AutoMapper中使用一個解析器填充目標對象屬性 – Sudheer

+0

否可能在這裏你不能因爲成員用於映射屬性用不同的名字或者忽略。但是爲了檢查assert.arequal,你可以使用mapper.assertconfigurationisvalid()來檢查是否相等,而不需要檢查single-2屬性。 –

回答

0

使用「forallmembers」 automapper的方法的任何其他方法調用,如果同樣的工作,你是doing.may是它會幫助你的。

相關問題