/// <summary> /// ctor /// </summary> public LangDataMapper() { //Stopwatch sw = new Stopwatch(); //sw.Start(); string entityName = typeof(TEntity).Name; ModelRule modelRule = ModelRule.Get <TModel>(); ModelRule entityRule = ModelRule.Get <TEntity>(); string lang = ResHelper.CurrentCultureName.ToLower(); _converter = GetConverter <TModel, TEntity>(); IMappingExpression <TModel, TEntity> expm2t = null; IMappingExpression <TEntity, TModel> expt2m = null; Mapper.Initialize(cfg => { expm2t = cfg.CreateMap <TModel, TEntity>(); expt2m = cfg.CreateMap <TEntity, TModel>(); }); if (_converter != null) { expt2m.ProjectUsing(_converter.EntityToModel); // expm2t.ConstructUsing(_converter.ModelToEntity.Compile()); 不知为何这句无效 } else { if (typeof(IMultiLanguage).IsAssignableFrom(typeof(TEntity))) { RefHelper.CallMethod(this, "MapperLangProperties", new Type[] { typeof(TModel), typeof(TEntity) }); } foreach (var r in modelRule.CollectionRules) { if (r.Attr.EntityType != null && Mapper.Configuration.FindTypeMapFor(r.ModelType, r.Attr.EntityType) == null) { Mapper.Initialize(cfg => { cfg.CreateMap(r.Attr.EntityType, r.ModelType); cfg.CreateMap(r.ModelType, r.Attr.EntityType); }); } expt2m.ForMember(r.Name, opt => opt.Ignore()); } foreach (var r in entityRule.CollectionRules) { expm2t.ForMember(r.Name, opt => opt.Ignore()); } } //Debug.WriteLine("Mapper Elapsed == " + sw.ElapsedMilliseconds); }
public void Dispose() { Action <object> dis = o => { if (o is IDisposable a) { a.Dispose(); } }; if (_accesser != null) { dis(_accesser); _accesser = null; } if (_converter != null) { dis(_converter); _converter = null; } if (_metadatas != null) { dis(_metadatas); _metadatas = null; } }
public TodolistService(ApplicationContext applicationContext, IModelEntityConverter <TodolistModel, ToDoList> TDconverter) { _applicationContext = applicationContext; this.TDconverter = TDconverter; }
public TodoConverter(IModelEntityConverter <TagModel, Tag> tagConverter) { _tagConverter = tagConverter; }
public TodoService(ApplicationContext applicationContext, IModelEntityConverter <TodoModel, Todo> todoConverter) { _applicationContext = applicationContext; _todoConverter = todoConverter; }
public DalSimple(IDalAccess <TEntity> accesser, IModelEntityConverter <TEntity> converter, IMetadatas metadatas) { _accesser = accesser; _converter = converter; _metadatas = metadatas; }
public DalSimple(IDalAccess <TEntity> accesser, IModelEntityConverter <TEntity> converter) : this(accesser, converter, getDefaultMetadatas <TEntity>()) { }
/// <summary> /// принимает конвертер инициализирует акцессор /// </summary> public DalSimple(IModelEntityConverter <TEntity> converter) : this(getDefaultAccesser(), converter) { }
public EntityModelProvider(IDalAccess <TEntity> _dal, IModelEntityConverter <TEntity> _converters) { dal = _dal; converters = _converters; }
public EntityModelProvider(IModelEntityConverter <TEntity> _converters) : this(null, _converters) { }