Skip to main content

Mapping samples

Select one delegate near the top of Program.cs, then run:

dotnet run --project mapping/samples/Valiant.Mapping.Samples

Program.cs is intentionally only a selector. Each folder is self-contained, and the Sample class owns the explanation of the behavior it invokes.

DelegateDemonstratesSource
Basic.Sample.RunThe smallest useful mapper: matching members mapped by convention into an immutable constructor targetBasic
ExplicitMapping.Sample.RunA custom source transform, a renamed target member, and an intentionally ignored target memberExplicitMapping
ConditionalMapping.Sample.RunNative if/else, a chained When condition, and the equivalent Fallback and Default APIsConditionalMapping
NullHandling.Sample.RunMapper-wide null policy, IgnoreNull, MapNull, AllowNull, and a fallback for an ignored nullNullHandling
FlatteningAndEnums.Sample.RunConvention-based flattening, unflattening, and compatible enum conversionFlatteningAndEnums
Composition.Sample.RunConstructor-injected mapper reuse for a nested object and collection elementsComposition
DependencyInjection.Sample.RunGenerated registration; typed mapper, non-generic facade, and factory; successful and missing Try APIsDependencyInjection

The basic and convention samples show what the generator can infer. Samples with a Configure override demonstrate behavior supported by both the debuggable runtime backend and the fast generated backend. The dependency injection sample leaves ValiantMappingMode.Auto selected, so Debug builds use the debuggable backend and Release builds use generated fast mapping.

Continue with Convention mapping, Explicit mapping, or Composition and dependency injection for the complete contracts and constraints.