private Expression GetCheckedValueOrNull(Expression value, Expression keyedAccess, IMemberMapperData mapperData) { if (HasSimpleEntries) { return(null); } if ((value.NodeType != Block) && (value.NodeType != Try) || mapperData.TargetIsDefinitelyUnpopulated()) { return(mapperData.SourceMember.IsEnumerable ? value.GetConversionTo(ValueType) : null); } var checkedAccess = GetAccessChecked(mapperData); var existingValue = checkedAccess.Variables.First(); if (value.NodeType == Try) { return(GetCheckedTryCatch((TryExpression)value, keyedAccess, checkedAccess, existingValue)); } var checkedValue = ((BlockExpression)value).Replace(keyedAccess, existingValue); return(checkedValue.Update( checkedValue.Variables.Append(existingValue), checkedValue.Expressions.Prepend(checkedAccess.Expressions.First()))); }
private static Expression GetTargetValidCheckOrNull(Type targetType, IMemberMapperData mapperData) { if (!mapperData.TargetMember.IsReadable || mapperData.TargetIsDefinitelyUnpopulated()) { return(null); } var targetIsOfDerivedType = GetTargetIsDerivedTypeCheck(targetType, mapperData); if (mapperData.TargetIsDefinitelyPopulated()) { return(targetIsOfDerivedType); } var targetIsNull = mapperData.TargetObject.GetIsDefaultComparison(); var targetIsValid = Expression.OrElse(targetIsNull, targetIsOfDerivedType); return(targetIsValid); }