private bool CannotBeReversed(out QualifiedMember targetMember, out string reason) { if (_valueCouldBeSourceMember == false) { targetMember = null; reason = $"configured value '{_dataSourceLambda.GetDescription(ConfigInfo)}' is not a source member"; return(true); } if (ConfigInfo.HasCondition) { targetMember = null; reason = $"configuration has condition '{ConfigInfo.GetConditionDescription(ConfigInfo)}'"; return(true); } if (!TargetMember.IsReadable) { targetMember = null; reason = $"target member '{GetTargetMemberPath()}' is not readable, so cannot be used as a source member"; return(true); } if (!_dataSourceLambda.IsSourceMember(out var sourceMemberLambda)) { targetMember = null; reason = $"configured value '{_dataSourceLambda.GetDescription(ConfigInfo)}' is not a source member"; return(true); } targetMember = sourceMemberLambda.ToTargetMemberOrNull( ConfigInfo.SourceType, ConfigInfo.MapperContext, out reason); if (targetMember != null) { return(false); } var sourceMember = sourceMemberLambda.ToSourceMember(ConfigInfo.MapperContext); var sourceMemberPath = sourceMember.GetFriendlySourcePath(ConfigInfo); reason = $"source member '{sourceMemberPath}' is not a useable target member. {reason}"; return(true); }
private void ThrowIfSimpleSourceForNonSimpleTargetMember(Type targetMemberType) { if ((targetMemberType == typeof(object)) || targetMemberType.IsSimple() || !ConfiguredSourceType.IsSimple() || ConversionOperatorExists(targetMemberType) || _configInfo.HasTargetMemberMatcher()) { return; } var sourceValue = (_customValueLambda != null) ? GetSourceValueDescription(_customValueLambda.Body) : _customValueLambdaInfo.GetDescription(_configInfo); throw new MappingConfigurationException(string.Format( CultureInfo.InvariantCulture, "{0} cannot be mapped to target type '{1}'", sourceValue, targetMemberType.GetFriendlyName())); }