0
일부 SharePoint 라이브러리에는 한 가지 문제가 있습니다. 내 '모델'개체를 'ListItem'개체에 매핑하고 싶습니다. 불행히도 'ListItem'개체에는 생성자가 없으므로 SharePoint 라이브러리 안에있는 함수로 초기화해야합니다. 맵핑 된 오브젝트의 인스턴스를 (맵핑하기 전에) 제공 할 수 있습니까?생성 된 개체 인스턴스를 매퍼에 전달
public void AddToList(Model model)
{
// 'new ListItem()' is fobbiden. 'CreateListItemInstance()'
// creates 'instance' using client context, list name which aren't
// inside 'model' object.
ListItem instance = this.CreateListItemInstance();
// (Model -> ListItem) It throws exception, because automapper
// try to create instance of ListItem.
ListItem parsedItem = Mapper.Map<ListItem>(model);
// I would like to have something like below:
// Mapper.Map<ListItem>(model).UseInstance(instance);
this.SharePointListItemRepository.Insert(parsedItem);
this.SharePointListItemRepository.Save();
}
업데이트 (2017년 12월 22일)는
난 매퍼 인스턴스를 전달할 ResolutionContext 사용하고 난 인스턴스 생성자를 대체 ConstructUsing 방법이 예를 사용 하였다. CreateMap<Model, ListItem>()
//Using 'ConstructUsing' method to use instance of Model
//(from resolutionContext) as constructor.
.ConstructUsing((source, resolutionContext) =>
(resolutionContext.Items["instance"] as ListItem))
//Mappings...
.AfterMap((source, destination) =>
{
destination["Title"] = source.Title;
});