Exemplo n.º 1
0
        public CollectionMapperContext(Type source, Type target, IMappingOptions options)
            : base(source, target, options)
        {
            SourceCollectionElementType = SourceInstance.Type.GetCollectionGenericType();
            TargetCollectionElementType = TargetInstance.Type.GetCollectionGenericType();

            IsSourceElementTypeBuiltIn = SourceCollectionElementType.IsBuiltInType(true);
            IsTargetElementTypeBuiltIn = TargetCollectionElementType.IsBuiltInType(true);

            IsSourceElementTypeStruct = !SourceCollectionElementType.IsClass;
            IsTargetElementTypeStruct = !TargetCollectionElementType.IsClass;

            SourceCollectionLoopingVar = Expression.Parameter(SourceCollectionElementType, "loopVar");

            if (options.CollectionItemEqualityComparer != null)
            {
                var updateCollectionMethodInfo = typeof(LinqExtensions).GetMethod(
                    nameof(LinqExtensions.Update), BindingFlags.Static | BindingFlags.NonPublic)
                                                 .MakeGenericMethod(SourceCollectionElementType, TargetCollectionElementType);

                UpdateCollection = Expression.Call(null, updateCollectionMethodInfo, Mapper, ReferenceTracker, SourceInstance,
                                                   Expression.Convert(TargetInstance, typeof(ICollection <>).MakeGenericType(TargetCollectionElementType)),
                                                   Expression.Convert(Expression.Constant(options.CollectionItemEqualityComparer.Compile()),
                                                                      typeof(Func <, ,>).MakeGenericType(SourceCollectionElementType, TargetCollectionElementType, typeof(bool))));
            }
        }
Exemplo n.º 2
0
        public CollectionMapperContext(Type source, Type target, IMappingOptions options)
            : base(source, target, options)
        {
            SourceCollectionElementType = SourceInstance.Type.GetCollectionGenericType();
            TargetCollectionElementType = TargetInstance.Type.GetCollectionGenericType();

            IsSourceElementTypeBuiltIn = SourceCollectionElementType.IsBuiltInType(true);
            IsTargetElementTypeBuiltIn = TargetCollectionElementType.IsBuiltInType(true);

            SourceCollectionLoopingVar = Expression.Parameter(SourceCollectionElementType, "loopVar");
        }
Exemplo n.º 3
0
        public DictionaryMapperContext( Mapping mapping ) : base( mapping )
        {
            var sourceCollectionElementKeyType = SourceCollectionElementType.GetGenericArguments()[ 0 ];
            var sourceCollectionElementValueType = SourceCollectionElementType.GetGenericArguments()[ 1 ];

            var targetCollectionElementKeyType = TargetCollectionElementType.GetGenericArguments()[ 0 ];
            var targetCollectionElementValueType = TargetCollectionElementType.GetGenericArguments()[ 1 ];

            SourceCollectionElementKey = Expression.Variable( sourceCollectionElementKeyType, "sourceKey" );
            SourceCollectionElementValue = Expression.Variable( sourceCollectionElementValueType, "sourceValue" );

            TargetCollectionElementKey = Expression.Variable( targetCollectionElementKeyType, "targetKey" );
            TargetCollectionElementValue = Expression.Variable( targetCollectionElementValueType, "targetValue" );
        }
Exemplo n.º 4
0
        public CollectionMapperContext(Mapping mapping) : base(mapping)
        {
            SourceCollectionElementType = SourceInstance.Type.GetCollectionGenericType();
            TargetCollectionElementType = TargetInstance.Type.GetCollectionGenericType();

            if (SourceCollectionElementType != null)
            {
                IsSourceElementTypeBuiltIn = SourceCollectionElementType.IsBuiltIn(true);
                SourceCollectionLoopingVar = Expression.Parameter(SourceCollectionElementType, "loopVar");
            }

            if (TargetCollectionElementType != null)
            {
                IsTargetElementTypeBuiltIn = TargetCollectionElementType.IsBuiltIn(true);
            }

            Continue = Expression.Label("LoopContinue");
            Break    = Expression.Label("LoopBreak");
        }