//------------------------------------------------------ //internal internal static void SetupGenericActionMappingForDto(Type dtoType, BizRunnerProfile profile, bool bizIn) { var baseTypeName = (bizIn ? typeof(GenericActionToBizDtoSetup <,>) : typeof(GenericActionFromBizDtoSetup <,>)).FullName; baseTypeName = baseTypeName.Substring(0, baseTypeName.IndexOf('`')); Type setupType = null, loopType = dtoType.BaseType; while (setupType == null && loopType != null) { if (loopType.FullName.StartsWith(baseTypeName)) { setupType = loopType; } else { loopType = loopType.BaseType; } } if (setupType == null) { throw new InvalidOperationException( $"You registered the DTO {dtoType.Name}, as a {(bizIn ? "bizInDto" : "bizOutDto")}, but it doesn't inherit from {baseTypeName}."); } var bizInOutType = setupType.GetGenericArguments()[0]; new SetupDtoMappingProfile(dtoType, bizInOutType, profile, bizIn); }
public SetupDtoMappingProfile(Type dtoType, Type bizInOutType, BizRunnerProfile profile, bool bizIn) { var myGeneric = bizIn ? typeof(SetupToBizDtoProfile <,>) : typeof(SetupFromBizDtoProfile <,>); var setupType = myGeneric.MakeGenericType(bizInOutType, dtoType); Activator.CreateInstance(setupType, new object[] { profile }); }
public SetupToBizDtoProfile(BizRunnerProfile profile) { dynamic dto = Activator.CreateInstance(typeof(TDtoIn)); var alterMapExp = dto.AlterDtoMapping; if (alterMapExp == null) { profile.CreateMap <TDtoIn, TBizIn>().IgnoreAllPropertiesWithAnInaccessibleSetter(); } else { alterMapExp(profile.CreateMap <TDtoIn, TBizIn>().IgnoreAllPropertiesWithAnInaccessibleSetter()); } }
public static IWrappedBizRunnerConfigAndMappings CreateWrappedConfig(IGenericBizRunnerConfig config, BizRunnerProfile bizInProfile, BizRunnerProfile bizOutProfile) { var bizInMapping = new MapperConfiguration(cfg => { //cfg.CreateMissingTypeMaps = false; cfg.AddProfile(bizInProfile); }); var bizOutMapping = new MapperConfiguration(cfg => { //cfg.CreateMissingTypeMaps = false; cfg.AddProfile(bizOutProfile); }); return(new WrappedBizRunnerConfigAndMappings(config, bizInMapping, bizOutMapping)); }