zoukankan      html  css  js  c++  java
  • 映射前和映射后的操作

    Occasionally, you might need to perform custom logic before or after a map occurs. These should be a rarity, as it's more obvious to do this work outside of AutoMapper. You can create global before/after map actions:

    Mapper.Initialize(cfg => {
      cfg.CreateMap<Source, Dest>()
        .BeforeMap((src, dest) => src.Value = src.Value + 10)
        .AfterMap((src, dest) => dest.Name = "John");
    });
    

    Or you can create before/after map callbacks during mapping:

    int i = 10;
    Mapper.Map<Source, Dest>(src, opt => {
        opt.BeforeMap((src, dest) => src.Value = src.Value + i);
        opt.AfterMap((src, dest) => dest.Name = HttpContext.Current.Identity.Name);
    });
    

    The latter configuration is helpful when you need contextual information fed into before/after map actions.

  • 相关阅读:
    决策表快速排序
    书摘
    读书笔记
    echarts x y轴设置
    echarts图类型设置
    echarts入门
    jqgride实现多选
    jqgride实现每一行的单选
    Mac react环境搭建
    两列布局,三列布局
  • 原文地址:https://www.cnblogs.com/Leman/p/5774007.html
Copyright © 2011-2022 走看看