Enum NullPropertyHandling
- Namespace
- ForgeMap
- Assembly
- ForgeMap.Abstractions.dll
Specifies how nullable source properties should be assigned to non-nullable destination properties. This setting only applies to reference type properties where the source has a nullable annotation and the destination does not.
public enum NullPropertyHandling
Fields
CoalesceToDefault = 2Coalesce to a type-appropriate default value:
target.X = source.X ?? <default>;The assignment always happens. If the source value is null, a non-null default is substituted (see type-aware default values documentation).CoalesceToNew = 4Coalesce to a new instance:
target.X = source.X ?? new T();Similar to CoalesceToDefault, but strictly requires an accessible parameterless constructor for reference types (emits FM0038 if missing). For forge-method properties, emitsnew TDest()when source is null (rather than calling the forge method with a null argument). Value types usedefault(T); collections use type-aware empty instances.NullForgiving = 0Use the null-forgiving operator:
target.X = source.X!;The assignment always happens. If the source value is null at runtime, the destination receives null (bypassing the compiler's nullable analysis). This is the default, matching AutoMapper's "assign through" behavior.SkipNull = 1Skip the assignment when the source is null:
if (source.X is { } value) target.X = value;The destination retains its constructor-initialized or default value.ThrowException = 3Throw an exception when the source is null:
target.X = source.X ?? throw new ArgumentNullException(nameof(source.X));Fail-fast behavior for strict null safety using a single-evaluation, coalesce-to-throw pattern.