Пример #1
0
        /// <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);
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
 public TodolistService(ApplicationContext applicationContext,
                        IModelEntityConverter <TodolistModel, ToDoList> TDconverter)
 {
     _applicationContext = applicationContext;
     this.TDconverter    = TDconverter;
 }
Пример #4
0
 public TodoConverter(IModelEntityConverter <TagModel, Tag> tagConverter)
 {
     _tagConverter = tagConverter;
 }
Пример #5
0
 public TodoService(ApplicationContext applicationContext, IModelEntityConverter <TodoModel, Todo> todoConverter)
 {
     _applicationContext = applicationContext;
     _todoConverter      = todoConverter;
 }
Пример #6
0
 public DalSimple(IDalAccess <TEntity> accesser, IModelEntityConverter <TEntity> converter, IMetadatas metadatas)
 {
     _accesser  = accesser;
     _converter = converter;
     _metadatas = metadatas;
 }
Пример #7
0
 public DalSimple(IDalAccess <TEntity> accesser, IModelEntityConverter <TEntity> converter) : this(accesser, converter, getDefaultMetadatas <TEntity>())
 {
 }
Пример #8
0
 /// <summary>
 /// принимает конвертер инициализирует акцессор
 /// </summary>
 public DalSimple(IModelEntityConverter <TEntity> converter) : this(getDefaultAccesser(), converter)
 {
 }
Пример #9
0
 public EntityModelProvider(IDalAccess <TEntity> _dal, IModelEntityConverter <TEntity> _converters)
 {
     dal        = _dal;
     converters = _converters;
 }
Пример #10
0
 public EntityModelProvider(IModelEntityConverter <TEntity> _converters) : this(null, _converters)
 {
 }