AutoMapper.Execution.TypeMapPlanBuilder.CreateNewDestinationFunc C# (CSharp) Method

CreateNewDestinationFunc() private method

private CreateNewDestinationFunc ( bool &constructorMapping ) : Expression
constructorMapping bool
return System.Linq.Expressions.Expression
        private Expression CreateNewDestinationFunc(out bool constructorMapping)
        {
            constructorMapping = false;
            if(_typeMap.DestinationCtor != null)
                return _typeMap.DestinationCtor.ReplaceParameters(_source, _context);

            if(_typeMap.ConstructDestinationUsingServiceLocator)
                return Call(MakeMemberAccess(_context, typeof(ResolutionContext).GetDeclaredProperty("Options")),
                    typeof(IMappingOperationOptions).GetDeclaredMethod("CreateInstance")
                        .MakeGenericMethod(_typeMap.DestinationTypeToUse)
                    );

            if(_typeMap.ConstructorMap?.CanResolve == true)
            {
                constructorMapping = true;
                return _typeMap.ConstructorMap.BuildExpression(this);
            }
#if NET45
            if(_typeMap.DestinationTypeToUse.IsInterface())
            {
                var ctor = Call(Constant(ObjectCreator.DelegateFactory), typeof(DelegateFactory).GetDeclaredMethod("CreateCtor", new[] { typeof(Type) }), Call(New(typeof(ProxyGenerator)), typeof(ProxyGenerator).GetDeclaredMethod("GetProxyType"), Constant(_typeMap.DestinationTypeToUse)));
                // We're invoking a delegate here
                return Invoke(ctor);
            }
#endif

            if(_typeMap.DestinationTypeToUse.IsAbstract())
                return Constant(null);

            if(_typeMap.DestinationTypeToUse.IsGenericTypeDefinition())
                return Constant(null);

            return DelegateFactory.GenerateConstructorExpression(_typeMap.DestinationTypeToUse);
        }