/// <summary> /// /// </summary> /// <typeparam name="TProfile"></typeparam> /// <param name="validate"></param> public void AddProfile <TProfile>(bool validate = false) where TProfile : Profile, new() { Configurators.Add(context => context.MapperConfiguration.AddProfile <TProfile>()); if (validate) { ValidateProfile(typeof(TProfile)); } }
public void AddProfiles(Assembly assembly) { var profileTypes = assembly .GetTypes() .Where(type => typeof(Profile).IsAssignableFrom(type) && !type.IsAbstract && !type.IsGenericType); foreach (var profileType in profileTypes) { Configurators.Add(mapper => mapper.AddProfile(profileType)); } }
/// <summary> /// 添加模块 /// </summary> /// <typeparam name="TModule"></typeparam> /// <param name="func">委托返回所有的枚举项值</param> /// <param name="func2">委托返回所有的枚举类型</param> public void Add <TModule>(Func <Assembly, Dictionary <string, Dictionary <int, string> > > func, Func <Assembly, Dictionary <string, string> > func2) { var assembly = typeof(TModule).Assembly; Configurators.Add(context => { Dictionary <string, Dictionary <int, string> > dic = new Dictionary <string, Dictionary <int, string> >(); Dictionary <string, string> dicType = new Dictionary <string, string>(); if (func != null) { dic = func(assembly); if (func2 == null) { throw new Exception("返回枚举类型的委托不能为空"); } dicType = func2(assembly); } else { var types = assembly.GetTypes().Where(p => p.IsEnum); foreach (var enumType in types) { FieldInfo[] fields = enumType.GetFields(BindingFlags.Static | BindingFlags.Public); var rs = new Dictionary <int, string>(); foreach (var item in fields) { var fieldValue = item.GetRawConstantValue(); var fieldDescription = item.GetDescription(); rs.Add((int)fieldValue, fieldDescription); } dic.Add(enumType.Name, rs); dicType.Add(enumType.Name, enumType.GetDescription()); } } foreach (var item in dic) { if (!context.Enums.ContainsKey(item.Key)) { context.Enums.Add(item.Key, item.Value); } } foreach (var item in dicType) { if (!context.EnumTypes.ContainsKey(item.Key)) { context.EnumTypes.Add(item.Key, item.Value); } } }); }
public void AddProfile <TProfile>(bool validate = false) where TProfile : Profile, new() { Configurators.Add(context => { context.MapperConfiguration.AddProfile <TProfile>(); }); if (validate) { ValidatingProfiles.Add <TProfile>(); } }
/// <summary> /// /// </summary> /// <typeparam name="TModule"></typeparam> /// <param name="validate"></param> public void AddMaps <TModule>(bool validate = false) { var assembly = typeof(TModule).Assembly; Configurators.Add(context => context.MapperConfiguration.AddMaps(assembly)); if (validate) { var profileTypes = assembly .DefinedTypes .Where(type => typeof(Profile).IsAssignableFrom(type) && !type.IsAbstract && !type.IsGenericType); foreach (var profileType in profileTypes) { ValidatingProfiles.Add(profileType); } } }
public void AddConfigurator(Action <IMapperConfigurationExpression> action) { Configurators.Add(action); }