public static Expression UseTargetInstance(IMemberMapperData mapperData, Expression contextAccess, Type targetType)
        {
            if (!contextAccess.Type.IsGenericType())
            {
                return(UseTargetMember(mapperData, contextAccess, targetType));
            }

            var targetInstanceAccess = mapperData
                                       .GetAppropriateMappingContext(contextAccess.Type.GetGenericTypeArguments())
                                       .TargetInstance;

            return(ConvertTargetType(targetType, targetInstanceAccess)
                ? targetInstanceAccess.GetConversionTo(targetType)
                : targetInstanceAccess);
        }
        public static Expression UseInstanceVariable(IMemberMapperData mapperData, Expression contextAccess, Type targetType)
        {
            if (!contextAccess.Type.IsGenericType())
            {
                return(UseTargetMember(mapperData, contextAccess, targetType));
            }

            var instanceVariableAccess = mapperData
                                         .GetAppropriateMappingContext(contextAccess.Type.GetGenericArguments())
                                         .InstanceVariable;

            return(targetType.IsAssignableFrom(instanceVariableAccess.Type)
                ? instanceVariableAccess
                : instanceVariableAccess.GetConversionTo(targetType));
        }
        private Expression GetTypeCheckConditionOrNull(IMemberMapperData mapperData)
        {
            var sourceType   = (SourceType == _allSourceTypes) ? typeof(object) : SourceType;
            var contextTypes = new[] { sourceType, TargetType };
            var context      = mapperData.GetAppropriateMappingContext(contextTypes);

            if (!TargetType.IsDerivedFrom(context.TargetType))
            {
                return(null);
            }

            var contextAccess = mapperData.GetAppropriateMappingContextAccess(contextTypes);

            if (contextAccess == mapperData.MappingDataObject)
            {
                return(null);
            }

            var targetAccess        = mapperData.GetTargetAccess(contextAccess, TargetType);
            var targetAccessNotNull = targetAccess.GetIsNotDefaultComparison();

            return(targetAccessNotNull);
        }