Exemplo n.º 1
0
            public override TEntity Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
            {
                var entityType = EntityProxyManager.GetType(args.NominalType);
                var ser        = BsonSerializer.SerializerRegistry.GetSerializer(entityType);

                return((TEntity)ser.Deserialize(context));
            }
Exemplo n.º 2
0
        void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context)
        {
            if (context.Mappers.Count > 0)
            {
                var contextType = context.ContextService.ContextType;
                var injection   = context.ContextService.Provider.GetService <IInjectionProvider>();

                context.Mappers.GroupBy(s => s.EntityType.Assembly)
                .Select(s => new { assembly = s.Key, types = s.Select(t => t.EntityType).Distinct().ToArray() })
                .ForEach(s => EntityProxyManager.CompileAll(contextType, s.assembly, s.types, injection));
            }
        }
        void IEntityContextPreInitializer.PreInitialize(EntityContextPreInitializeContext context)
        {
            if (context.Mappers.Count > 0)
            {
                var injection = context.Service.Provider.GetService <IInjectionProvider>();

                foreach (var assembly in context.Mappers.GroupBy(s => s.EntityType.Assembly))
                {
                    EntityProxyManager.CompileAll(assembly.Key, injection);
                }
            }
        }
Exemplo n.º 4
0
        protected override Expression VisitNew(NewExpression node)
        {
            var elementType = node.Type;

            if (typeof(IEntity).IsAssignableFrom(elementType))
            {
                if (elementType.IsNotCompiled())
                {
                    elementType = EntityProxyManager.GetType(elementType);
                    return(Expression.New(elementType));
                }
            }

            return(base.VisitNew(node));
        }
Exemplo n.º 5
0
        protected override Expression VisitNew(NewExpression node)
        {
            var elementType = node.Type;

            if (typeof(IEntity).IsAssignableFrom(elementType) && elementType.IsNotCompiled())
            {
                var contextType = _transContext.ContextType;
                elementType = EntityProxyManager.GetType(contextType, elementType);
            }

            if (elementType != node.Type)
            {
                var types     = node.Arguments.Select(s => s.Type).ToArray();
                var arguments = node.Arguments.Select(s => Visit(s));
                var consInfo  = elementType.GetConstructor(types);
                return(Expression.New(consInfo, arguments));
            }

            return(base.VisitNew(node));
        }