public static IObjectMappingData ForRoot <TSource, TTarget>(
            TSource source,
            TTarget target,
            IMappingContext mappingContext)
        {
            MappingTypes mappingTypes;

            if ((target == null) && (typeof(TTarget) == typeof(object)))
            {
                // This is a 'create new' mapping where the target type has come
                // through as 'object'. This happens when you use .ToANew<dynamic>(),
                // and I can't see how to differentiate that from .ToANew<object>().
                // Given that the former is more likely and that people asking for
                // .ToANew<object>() are doing something weird, default the target
                // type to ExpandoObject:
                mappingTypes = MappingTypes.For(source, default(ExpandoObject));

                return(Create(
                           source,
                           default(ExpandoObject),
                           null,
                           mappingTypes,
                           mappingContext));
            }

            mappingTypes = MappingTypes.For(source, target);

            return(Create(
                       source,
                       target,
                       null,
                       mappingTypes,
                       mappingContext));
        }
        public static IObjectMappingData ForElement <TSource, TTarget>(
            TSource source,
            TTarget target,
            int enumerableIndex,
            IObjectMappingData parent)
        {
            var mapperKey = new ElementObjectMapperKey(MappingTypes.For(source, target));

            return(Create(
                       source,
                       target,
                       enumerableIndex,
                       mapperKey,
                       parent));
        }
        object IObjectMappingDataFactoryBridge.ForChild <TSource, TTarget>(object childMembersSource, object parent)
        {
            var mapperKey = new ChildObjectMapperKey(
                MappingTypes.For(default(TSource), default(TTarget)),
                (IChildMembersSource)childMembersSource);

            var parentMappingData = (IObjectMappingData)parent;

            return(Create(
                       default(TSource),
                       default(TTarget),
                       default(int?),
                       mapperKey,
                       parentMappingData));
        }
        private static IObjectMappingData Create <TDeclaredSource, TDeclaredTarget>(
            TDeclaredSource source,
            TDeclaredTarget target,
            int?enumerableIndex,
            Func <MappingTypes, IMappingContext, ObjectMapperKeyBase> mapperKeyFactory,
            IMappingContext mappingContext,
            IObjectMappingData parent = null)
        {
            var mappingTypes = MappingTypes.For(source, target);
            var mapperKey    = mapperKeyFactory.Invoke(mappingTypes, mappingContext);

            if (mappingTypes.RuntimeTypesAreTheSame)
            {
                return(new ObjectMappingData <TDeclaredSource, TDeclaredTarget>(
                           source,
                           target,
                           enumerableIndex,
                           mapperKey,
                           mappingContext,
                           parent));
            }

            if (Constants.ReflectionNotPermitted)
            {
                var createCaller = GetPartialTrustMappingDataCreator <TDeclaredSource, TDeclaredTarget>(mappingTypes);

                return((IObjectMappingData)createCaller.Invoke(
                           _bridge,
                           source,
                           target,
                           enumerableIndex,
                           mapperKey,
                           mappingContext,
                           parent));
            }

            var constructionFunc = GetMappingDataCreator <TDeclaredSource, TDeclaredTarget>(mappingTypes);

            return(constructionFunc.Invoke(
                       source,
                       target,
                       enumerableIndex,
                       mapperKey,
                       mappingContext,
                       parent));
        }
        public static IObjectMappingData ForChild <TSource, TTarget>(
            TSource source,
            TTarget target,
            int?enumerableIndex,
            string targetMemberRegistrationName,
            int dataSourceIndex,
            IObjectMappingData parent)
        {
            var mapperKey = new ChildObjectMapperKey(
                MappingTypes.For(source, target),
                targetMemberRegistrationName,
                dataSourceIndex);

            return(Create(
                       source,
                       target,
                       enumerableIndex,
                       mapperKey,
                       parent));
        }