You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 34fbd20
Browse filesBrowse the repository at this point in the historyBrowse files
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
Copy file name to clipboardExpand all lines: docs/source/Conditional-mapping.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ If you have a resolver, see [here](Custom-value-resolvers.html#resolvers-and-con
25
25
26
26
## Nullable source members
27
27
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)`.
29
29
30
30
This makes the common PATCH scenario -- "only assign members the caller actually supplied" -- expressible with `ForAllMembers`:
// destination.Count is still 7 -- the null source member was skipped
49
49
```
50
50
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:
52
52
53
53
```c#
54
54
cfg.CreateMap<Source, Destination>()
@@ -98,7 +98,7 @@ public interface ICondition<in TSource, in TDestination, in TMember>
98
98
}
99
99
```
100
100
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).
102
102
103
103
`IPreCondition<TSource, TDestination>` is evaluated before source member resolution and does not have access to member values:
0 commit comments