Skip to content

Commit 34fbd20

Browse files
jbogardclaude
andcommitted
Clarify when Condition receives the pre-conversion source value
The docs stated the pre-conversion rule unconditionally, but a condition whose member parameter cannot hold the resolved source value falls back to the mapped value. Say so up front rather than only in the ForMember paragraph. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wm2m61jXrAs4FheXR5TufH
1 parent d57b329 commit 34fbd20

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎docs/source/Conditional-mapping.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ If you have a resolver, see [here](Custom-value-resolvers.html#resolvers-and-con
2525

2626
## Nullable source members
2727

28-
The source member value passed to `Condition` is the value resolved from the source object, *before* it is converted to the destination member type. This matters when the source member is a `Nullable<T>` and the destination member is a non-nullable `T`: the condition sees `null`, not `default(T)`.
28+
When the condition's source member parameter can hold it, `Condition` receives the value resolved from the source object *before* it is converted to the destination member type; otherwise it receives the converted value. This matters when the source member is a `Nullable<T>` and the destination member is a non-nullable `T`, because the parameter type decides whether the condition sees `null` or `default(T)`.
2929

3030
This makes the common PATCH scenario -- "only assign members the caller actually supplied" -- expressible with `ForAllMembers`:
3131

@@ -48,7 +48,7 @@ mapper.Map(new Source { Count = null }, destination);
4848
// destination.Count is still 7 -- the null source member was skipped
4949
```
5050

51-
Note that `ForAllMembers` types the source member parameter as `object`, which is what allows a `Nullable<T>` to arrive intact. A `ForMember` condition types both member parameters as the *destination* member type, so a `Nullable<T>` source cannot be represented there and the condition receives the converted value instead (`0` for `int`, `false` for `bool`). To check a nullable source member for a single member, use a `PreCondition` against the source object:
51+
`ForAllMembers` types the source member parameter as `object`, which is what allows a `Nullable<T>` to arrive intact. A `ForMember` condition types both member parameters as the *destination* member type, so a `Nullable<T>` source cannot be represented there and the condition falls back to the converted value (`0` for `int`, `false` for `bool`). To check a nullable source member for a single member, use a `PreCondition` against the source object:
5252

5353
```c#
5454
cfg.CreateMap<Source, Destination>()
@@ -98,7 +98,7 @@ public interface ICondition<in TSource, in TDestination, in TMember>
9898
}
9999
```
100100

101-
As with the lambda overloads, `sourceMember` is the value resolved from the source object before conversion to the destination member type -- see [Nullable source members](#nullable-source-members).
101+
`sourceMember` follows the same rule as the lambda overloads: the pre-conversion source value when `TMember` can hold it, the converted value otherwise -- see [Nullable source members](#nullable-source-members).
102102

103103
`IPreCondition<TSource, TDestination>` is evaluated before source member resolution and does not have access to member values:
104104

0 commit comments

Comments
 (0)